diff --git a/queue.c b/queue.c index e1827da..860ad94 100644 --- a/queue.c +++ b/queue.c @@ -22,9 +22,9 @@ */ #include -#include #include -#include + +#include "stringhandling.h" struct queue_entry_t { void *data; @@ -38,11 +38,9 @@ struct queue_t { struct queue_t *new_queue(void) { - struct queue_t *q = malloc(sizeof(struct queue_t)); - if (q) { - q->head = NULL; - q->tail = NULL; - } + struct queue_t *q = allocMem(sizeof(struct queue_t)); + q->head = NULL; + q->tail = NULL; return q; } @@ -51,11 +49,7 @@ int queue_add(struct queue_t *q, void *data) struct queue_entry_t *tmp; assert(data); - tmp = malloc(sizeof(struct queue_entry_t)); - if (!tmp) { - printf("Unable to allocate memory for queue entry.\n"); - return 0; - } + tmp = allocMem(sizeof(struct queue_entry_t)); tmp->data = data; tmp->next = NULL; if (!q->tail) { diff --git a/softsynth.c b/softsynth.c index 0b9f76f..9c5af80 100644 --- a/softsynth.c +++ b/softsynth.c @@ -45,11 +45,7 @@ static void queue_add_cmd(enum command_t cmd, enum adjust_t adj, int value) struct espeak_entry_t *entry; int added = 0; - entry = malloc(sizeof(struct espeak_entry_t)); - if (!entry) { - perror("unable to allocate memory for queue entry"); - return; - } + entry = allocMem(sizeof(struct espeak_entry_t)); entry->cmd = cmd; entry->adjust = adj; entry->value = value; @@ -67,11 +63,7 @@ static void queue_add_text(char *txt, size_t length) struct espeak_entry_t *entry; int added = 0; - entry = malloc(sizeof(struct espeak_entry_t)); - if (!entry) { - perror("unable to allocate memory for queue entry"); - return; - } + entry = allocMem(sizeof(struct espeak_entry_t)); entry->cmd = CMD_SPEAK_TEXT; entry->adjust = ADJ_SET; entry->buf = strdup(txt); diff --git a/stringhandling.h b/stringhandling.h index 1353391..a7d7cea 100644 --- a/stringhandling.h +++ b/stringhandling.h @@ -20,6 +20,8 @@ #ifndef __STRINGHANDLING_H #define __STRINGHANDLING_H +#include + extern char *EMPTYSTRING; void *allocMem(size_t n);