chiark / gitweb /
sysv-generator: fix memory leak on failure
[elogind.git] / src / sysv-generator / sysv-generator.c
index 2f24ef2561ba1eb2a7cb5733037936051f6529f3..89c0e7c67d6ab87d1f33893df12232bfd70acde4 100644 (file)
@@ -755,13 +755,11 @@ static int enumerate_sysv(LookupPaths lp, Hashmap *all_services) {
                         service->name = name;
                         service->path = fpath;
 
                         service->name = name;
                         service->path = fpath;
 
-                        r = load_sysv(service);
-                        if (r < 0)
-                                continue;
-
                         r = hashmap_put(all_services, service->name, service);
                         r = hashmap_put(all_services, service->name, service);
-                        if (r < 0)
+                        if (r < 0) {
+                                free(service);
                                 return log_oom();
                                 return log_oom();
+                        }
 
                         name = fpath = NULL;
                 }
 
                         name = fpath = NULL;
                 }
@@ -942,6 +940,12 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
                 return EXIT_FAILURE;
         }
 
+        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)
         HASHMAP_FOREACH(service, all_services, j) {
                 q = fix_order(service, all_services);
                 if (q < 0)