mirror of
https://github.com/topjohnwu/selinux.git
synced 2024-11-24 12:09:50 +00:00
libselinux: getsebool: always free names
When getsebool's main() fails to allocate memory for the boolean names, it returns without freeing variables first, even though other errors do this (with label "out"). This silences a warning reported by clang's static analyzer. Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
This commit is contained in:
parent
a9094fae2c
commit
bb3f428c08
@ -15,7 +15,7 @@ static __attribute__ ((__noreturn__)) void usage(const char *progname)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i, get_all = 0, rc = 0, active, pending, len = 0, opt;
|
||||
char **names;
|
||||
char **names = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "a")) > 0) {
|
||||
switch (opt) {
|
||||
@ -55,7 +55,7 @@ int main(int argc, char **argv)
|
||||
if (argc < 2)
|
||||
usage(argv[0]);
|
||||
len = argc - 1;
|
||||
names = malloc(sizeof(char *) * len);
|
||||
names = calloc(len, sizeof(char *));
|
||||
if (!names) {
|
||||
fprintf(stderr, "%s: out of memory\n", argv[0]);
|
||||
return 2;
|
||||
@ -65,7 +65,8 @@ int main(int argc, char **argv)
|
||||
if (!names[i]) {
|
||||
fprintf(stderr, "%s: out of memory\n",
|
||||
argv[0]);
|
||||
return 2;
|
||||
rc = 2;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user