]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
scsi_id: use _cleanup_free_ on buffer allocated by get_file_options
authorFilipe Brandenburger <filbranden@google.com>
Thu, 7 Jun 2018 21:32:07 +0000 (14:32 -0700)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 8 Jun 2018 13:15:02 +0000 (15:15 +0200)
This simplifies the code a bit and hopefully fixes Coverity finding
CID 1382966. There was not actually a resource leak here (Coverity
seemed to be confused by thinking log_oom() could actually return 0),
but the fix doesn't hurt and should make this code more resilient to
future refactorings.

Tested: builds fine, manually called scsi_id, seems to work ok.

src/udev/scsi_id/scsi_id.c

index 217fb2f8abe3207604f34f2fe7c8941adc3793f7..59ef121cbe670823e79e1ca83025ad8f6e6f2bb4 100644 (file)
@@ -164,7 +164,7 @@ static int get_file_options(struct udev *udev,
                             const char *vendor, const char *model,
                             int *argc, char ***newargv)
 {
-        char *buffer;
+        _cleanup_free_ char *buffer = NULL;
         _cleanup_fclose_ FILE *f;
         char *buf;
         char *str1;
@@ -295,14 +295,13 @@ static int get_file_options(struct udev *udev,
                                 (*newargv)[c] = buffer;
                                 for (c = 1; c < *argc; c++)
                                         (*newargv)[c] = strsep(&buffer, " \t");
+                                buffer = NULL;
                         }
                 } else {
                         /* No matches  */
                         retval = 1;
                 }
         }
-        if (retval != 0)
-                free(buffer);
         return retval;
 }