mirror of
https://github.com/linux-speakup/espeakup.git
synced 2026-08-18 13:59:11 +02:00
change code to use allocMem wrapper for memory allocation
One of the new string handling routines is a wrapper for allocating memory. This commit changes the rest of the code to take advantage of that wrapper.
This commit is contained in:
parent
6180ff6e49
commit
3b4b6d0cbc
3 changed files with 10 additions and 22 deletions
18
queue.c
18
queue.c
|
|
@ -22,9 +22,9 @@
|
|||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#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) {
|
||||
|
|
|
|||
12
softsynth.c
12
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);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
#ifndef __STRINGHANDLING_H
|
||||
#define __STRINGHANDLING_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
extern char *EMPTYSTRING;
|
||||
|
||||
void *allocMem(size_t n);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue