libselinux: getdefaultcon: free memory on multiple same arguments
Do not leak memory if program arguments get specified more than once. Found by clang-anlyzer. getdefaultcon.c:52:3: warning: Potential leak of memory pointed to by 'level' [unix.Malloc] fprintf(stderr, ^~~~~~~~~~~~~~~ getdefaultcon.c:52:3: warning: Potential leak of memory pointed to by 'role' [unix.Malloc] fprintf(stderr, ^~~~~~~~~~~~~~~ getdefaultcon.c:52:3: warning: Potential leak of memory pointed to by 'service' [unix.Malloc] fprintf(stderr, ^~~~~~~~~~~~~~~ Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
This commit is contained in:
parent
411c5a5458
commit
db69a3d362
1 changed files with 3 additions and 0 deletions
|
@ -28,12 +28,15 @@ int main(int argc, char **argv)
|
|||
while ((opt = getopt(argc, argv, "l:r:s:v")) > 0) {
|
||||
switch (opt) {
|
||||
case 'l':
|
||||
free(level);
|
||||
level = strdup(optarg);
|
||||
break;
|
||||
case 'r':
|
||||
free(role);
|
||||
role = strdup(optarg);
|
||||
break;
|
||||
case 's':
|
||||
free(service);
|
||||
service = strdup(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
|
|
Loading…
Reference in a new issue