[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
patch: removes memory leaks from speechd-up
From: |
C . M . Brannon |
Subject: |
patch: removes memory leaks from speechd-up |
Date: |
Mon, 25 Feb 2008 15:13:03 -0600 |
Hello,
I was looking through the speechd-up code from CVS, and I found some memory
leaks. ssml_text and utf8_text are never freed.
I don't know whether this is the correct place to send patches, but I am
attaching my fix.
I don't run a Speakup kernel, so I haven't tested this. But the diff
is fairly minimal.
Regards,
-- Chris
-------------- next part --------------
diff -Naupr speechd-up/speechd-up.c speechd-up.new/speechd-up.c
--- speechd-up/speechd-up.c 2008-02-25 15:04:55.000000000 -0600
+++ speechd-up.new/speechd-up.c 2008-02-25 15:05:59.000000000 -0600
@@ -60,6 +60,13 @@ char *spd_spk_pid_file;
void spd_spk_reset(int sig);
+/* Lifted directly from speechd/src/modules/module_utils.c. */
+void
+xfree(void *data)
+{
+ if (data != NULL) free(data);
+}
+
void
index_marker_callback(size_t msg_id, size_t client_id, SPDNotificationType
type,
char *index_mark)
@@ -319,7 +326,7 @@ recode_text(char *text)
int
speak(char *text)
{
- char *ssml_text;
+ char *ssml_text = NULL;
/* Check whether text contains more than one
printable character. If so, use spd_say,
otherwise use say_single_character.
@@ -330,8 +337,8 @@ speak(char *text)
int printables = 0;
int i;
- char *utf8_text;
- int spd_ret;
+ char *utf8_text = NULL;
+ int spd_ret = 0, ret = 0;
char character[2];
assert(text);
@@ -351,17 +358,23 @@ speak(char *text)
spd_ret = say_single_character(utf8_text);
}else{
utf8_text = recode_text(text);
- if (utf8_text == NULL) return -1;
- ssml_text = malloc(strlen(utf8_text)+16);
- snprintf(ssml_text, strlen(text)+16, "<speak>%s</speak>", utf8_text);
- LOG(5, "Sending to speechd as text: |%s|", ssml_text);
- spd_ret = spd_say(conn, SPD_MESSAGE, ssml_text);
+ if (utf8_text == NULL)
+ ret = -1;
+ else {
+ ssml_text = malloc(strlen(utf8_text)+16);
+ snprintf(ssml_text, strlen(text)+16, "<speak>%s</speak>", utf8_text);
+ LOG(5, "Sending to speechd as text: |%s|", ssml_text);
+ spd_ret = spd_say(conn, SPD_MESSAGE, ssml_text);
+ }
}
+ xfree(utf8_text);
+ xfree(ssml_text);
+
if (spd_ret != 0)
- return -2;
+ ret = -2;
- return 0;
+ return ret;
}
int
- patch: removes memory leaks from speechd-up,
C . M . Brannon <=