From 2e3b44d7b4a2cd979d53f7d9b1886c28d6dbe69c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 25 Apr 2015 19:10:00 +0200 Subject: patch memory leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- doc/examples/telephony-and-music/monitor.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'doc') diff --git a/doc/examples/telephony-and-music/monitor.c b/doc/examples/telephony-and-music/monitor.c index 8f8e244..34b90a4 100644 --- a/doc/examples/telephony-and-music/monitor.c +++ b/doc/examples/telephony-and-music/monitor.c @@ -27,7 +27,7 @@ static int is_moc_playing(void) * time, causing chaos. */ static int callback(const char *message, void *user_data) { - char *msg; + char *msg = NULL; size_t len = 0; while ((len < 2047) && message[len]) len++; @@ -41,18 +41,18 @@ static int callback(const char *message, void *user_data) ssize_t pid; int requests_pause; if (begin == NULL) - return 1; + goto done; *begin++ = 0; pid = (ssize_t)atoll(msg); if (pid < 1) /* We need a real PID, too bad there is no convient way to detect if it dies. */ - return 1; + goto done; if ((strstr(begin, "force-pause ") == begin) || !strcmp(begin, "force-pause")) requests_pause = 1; else if ((strstr(begin, "unforce-pause ") == begin) || !strcmp(begin, "unforce-pause")) requests_pause = 0; else - return 1; + goto done; if ((size_t)pid >= pausers_size) { pausers = realloc(pausers, (size_t)(pid + 1) * sizeof(char)); t(pausers == NULL); /* Let's ignore the memory leak. */ @@ -67,12 +67,16 @@ static int callback(const char *message, void *user_data) } } /* END run as in a separate thread */ - return 1; + goto done; (void) user_data; fail: perror("monitor"); return -1; + +done: + free(msg); + return 1; } -- cgit v1.2.3-70-g09d2