summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe Brandenburger <filbranden@google.com>2018-06-07 14:32:07 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-06-08 15:15:02 +0200
commit3ad97058247a3f7f274a515d279e9b8428de002e (patch)
treec7351f71e8d51bfca730c8d4904d2dd458cff782 /src
parent6cdf635de0741c5b7921afc3d126f8bd3b5aca2d (diff)
downloadsystemd-3ad97058247a3f7f274a515d279e9b8428de002e.tar.gz
scsi_id: use _cleanup_free_ on buffer allocated by get_file_options
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.
Diffstat (limited to 'src')
-rw-r--r--src/udev/scsi_id/scsi_id.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index 217fb2f8ab..59ef121cbe 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -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;
}