]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: fix memleak in GetUnitFileLinks method
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Nov 2022 22:06:46 +0000 (07:06 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 2 Nov 2022 00:09:48 +0000 (09:09 +0900)
src/core/dbus-manager.c

index 919aa58cdee2d21b2fb4123ad739611c32f65907..88f098ec86c33441672a349d4ab0117fad0c2450 100644 (file)
@@ -2647,21 +2647,27 @@ static int method_get_unit_file_links(sd_bus_message *message, void *userdata, s
                 (runtime ? UNIT_FILE_RUNTIME : 0);
 
         r = unit_file_disable(LOOKUP_SCOPE_SYSTEM, flags, NULL, p, &changes, &n_changes);
-        if (r < 0)
-                return log_error_errno(r, "Failed to get file links for %s: %m", name);
+        if (r < 0) {
+                log_error_errno(r, "Failed to get file links for %s: %m", name);
+                goto finish;
+        }
 
         for (i = 0; i < n_changes; i++)
                 if (changes[i].type == INSTALL_CHANGE_UNLINK) {
                         r = sd_bus_message_append(reply, "s", changes[i].path);
                         if (r < 0)
-                                return r;
+                                goto finish;
                 }
 
         r = sd_bus_message_close_container(reply);
         if (r < 0)
-                return r;
+                goto finish;
 
-        return sd_bus_send(NULL, reply, NULL);
+        r = sd_bus_send(NULL, reply, NULL);
+
+finish:
+        install_changes_free(changes, n_changes);
+        return r;
 }
 
 static int method_get_job_waiting(sd_bus_message *message, void *userdata, sd_bus_error *error) {