diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-04-25 19:10:00 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-04-25 19:10:00 +0200 |
commit | 2e3b44d7b4a2cd979d53f7d9b1886c28d6dbe69c (patch) | |
tree | 11f1484e235eab3aa640f8cf258ca71bf1d62ebf | |
parent | update dist (diff) | |
download | bus-2e3b44d7b4a2cd979d53f7d9b1886c28d6dbe69c.tar.gz bus-2e3b44d7b4a2cd979d53f7d9b1886c28d6dbe69c.tar.bz2 bus-2e3b44d7b4a2cd979d53f7d9b1886c28d6dbe69c.tar.xz |
patch memory leak
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to '')
-rw-r--r-- | doc/examples/telephony-and-music/monitor.c | 14 |
1 files changed, 9 insertions, 5 deletions
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; } |