chiark / gitweb /
sysv-generator: fix memory leak on failure
authorLennart Poettering <lennart@poettering.net>
Wed, 14 Jan 2015 21:31:03 +0000 (22:31 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 14 Jan 2015 22:18:33 +0000 (23:18 +0100)
This fixes a memory leak introduced by
1ed0c19f81fd13cdf283c6def0168ce122a853a9

src/sysv-generator/sysv-generator.c

index 2f24ef2..89c0e7c 100644 (file)
@@ -755,13 +755,11 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
                         service->name = name;
                         service->path = fpath;
 
-                        r = load_sysv(service);
-                        if (r < 0)
-                                continue;
-
                         r = hashmap_put(all_services, service->name, service);
-                        if (r < 0)
+                        if (r < 0) {
+                                free(service);
                                 return log_oom();
+                        }
 
                         name = fpath = NULL;
                 }
@@ -943,6 +941,12 @@ int main(int argc, char *argv[]) {
         }
 
         HASHMAP_FOREACH(service, all_services, j) {
+                q = load_sysv(service);
+                if (q < 0)
+                        continue;
+        }
+
+        HASHMAP_FOREACH(service, all_services, j) {
                 q = fix_order(service, all_services);
                 if (q < 0)
                         continue;