chiark / gitweb /
journal: fix a few bad memory accesses and leaks
authorLennart Poettering <lennart@poettering.net>
Fri, 30 Dec 2011 21:15:58 +0000 (22:15 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 30 Dec 2011 21:16:04 +0000 (22:16 +0100)
src/journal/journal-rate-limit.c
src/journal/journald.c

index f69ab2770f72e74dad611f8f5be3a1d6fd349e01..243ff2a37850335394818c819398cf4e06236d23 100644 (file)
@@ -111,6 +111,8 @@ void journal_rate_limit_free(JournalRateLimit *r) {
 
         while (r->lru)
                 journal_rate_limit_group_free(r->lru);
+
+        free(r);
 }
 
 static bool journal_rate_limit_group_expired(JournalRateLimitGroup *g, usec_t ts) {
index b290b5d2c063bb0c42639a4f090a4a5690424871..8d6b3ab438160cc803e1d1f9d1ee3866ae4b164e 100644 (file)
@@ -378,11 +378,22 @@ static char *shortened_cgroup_path(pid_t pid) {
         if (streq(init_path, "/"))
                 init_path[0] = 0;
 
-        if (startswith(process_path, init_path))
-                path = process_path + strlen(init_path);
-        else
+        if (startswith(process_path, init_path)) {
+                char *p;
+
+                p = strdup(process_path + strlen(init_path));
+                if (!p) {
+                        free(process_path);
+                        free(init_path);
+                        return NULL;
+                }
+                path = p;
+        } else {
                 path = process_path;
+                process_path = NULL;
+        }
 
+        free(process_path);
         free(init_path);
 
         return path;
@@ -544,7 +555,7 @@ static void dispatch_message(Server *s,
                              struct timeval *tv,
                              int priority) {
         int rl;
-        char *path, *c;
+        char *path = NULL, *c;
 
         assert(s);
         assert(iovec || n == 0);
@@ -1828,6 +1839,8 @@ static void server_done(Server *s) {
 
         if (s->rate_limit)
                 journal_rate_limit_free(s->rate_limit);
+
+        free(s->buffer);
 }
 
 int main(int argc, char *argv[]) {