]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
coredump: use a cleanup handler for destroying iovw objects
authorLennart Poettering <lennart@poettering.net>
Thu, 10 Aug 2023 10:10:47 +0000 (12:10 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 10 Aug 2023 10:10:47 +0000 (12:10 +0200)
src/basic/io-util.h
src/coredump/coredump.c

index 3ad8267962c87b178f3cddafd1af52ba6852abf9..4f7989e66d3caede52b260def71fdc6f915745c6 100644 (file)
@@ -93,6 +93,9 @@ struct iovec_wrapper {
 struct iovec_wrapper *iovw_new(void);
 struct iovec_wrapper *iovw_free(struct iovec_wrapper *iovw);
 struct iovec_wrapper *iovw_free_free(struct iovec_wrapper *iovw);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct iovec_wrapper*, iovw_free_free);
+
 void iovw_free_contents(struct iovec_wrapper *iovw, bool free_vectors);
 
 int iovw_put(struct iovec_wrapper *iovw, void *data, size_t len);
index 8ae4a9f63faca9eed936a0fb3328a043ca7be94e..8469ab297c36c599efa7bc39f4afccf500910a3f 100644 (file)
@@ -1363,8 +1363,8 @@ static int gather_pid_metadata(struct iovec_wrapper *iovw, Context *context) {
 }
 
 static int process_kernel(int argc, char* argv[]) {
+        _cleanup_(iovw_free_freep) struct iovec_wrapper *iovw = NULL;
         Context context = {};
-        struct iovec_wrapper *iovw;
         int r;
 
         /* When we're invoked by the kernel, stdout/stderr are closed which is dangerous because the fds
@@ -1386,12 +1386,12 @@ static int process_kernel(int argc, char* argv[]) {
         /* Collect all process metadata passed by the kernel through argv[] */
         r = gather_pid_metadata_from_argv(iovw, &context, argc - 1, argv + 1);
         if (r < 0)
-                goto finish;
+                return r;
 
         /* Collect the rest of the process metadata retrieved from the runtime */
         r = gather_pid_metadata(iovw, &context);
         if (r < 0)
-                goto finish;
+                return r;
 
         if (!context.is_journald)
                 /* OK, now we know it's not the journal, hence we can make use of it now. */
@@ -1409,13 +1409,9 @@ static int process_kernel(int argc, char* argv[]) {
         }
 
         if (context.is_journald || context.is_pid1)
-                r = submit_coredump(&context, iovw, STDIN_FILENO);
-        else
-                r = send_iovec(iovw, STDIN_FILENO);
+                return submit_coredump(&context, iovw, STDIN_FILENO);
 
- finish:
-        iovw = iovw_free_free(iovw);
-        return r;
+        return send_iovec(iovw, STDIN_FILENO);
 }
 
 static int process_backtrace(int argc, char *argv[]) {