]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
scsi_id: fix memory leak of option_get_synopsis() return value
authorLuca Boccassi <luca.boccassi@gmail.com>
Tue, 5 May 2026 12:55:00 +0000 (13:55 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Tue, 5 May 2026 12:55:00 +0000 (13:55 +0100)
option_get_synopsis() returns a heap-allocated string. Capture it in
a _cleanup_free_ variable so it is freed after being used in the log
message.

CID#1657828

Follow-up for 05fea7df1bd6579dc382455626e0e84acb2a8912

src/udev/scsi_id/scsi_id.c

index 295819351d19b4113ed636e118ba7cf38f34729d..93b65816e497e51fe80a599ae802f43f3dc81167 100644 (file)
@@ -328,10 +328,13 @@ static int per_dev_options(struct scsi_id_device *dev_scsi, int *good_bad, enum
                         r = parse_page_code(opts.arg, page_code);
                         if (r < 0)
                                 return r;
-                } else
+                } else {
+                        _cleanup_free_ char *synopsis =
+                                option_get_synopsis(opts.opt, "/", /* show_metavar=*/ false);
                         return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                "Option %s not supported in the config file.",
-                                               strnull(option_get_synopsis(opts.opt, "/", /* show_metavar=*/ false)));
+                                               strnull(synopsis));
+                }
 
         return 0;
 }