commit: 8b894d54723b6b172903dbf6599cec7125c1ec68
parent e698a0a4cd0d41c17e13ffaf3d81a8762bf88f9d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 28 Jul 2023 12:02:42 +0200
cmd/id: Fix memory allocation issues
Diffstat:
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/cmd/id.c b/cmd/id.c
@@ -230,6 +230,7 @@ main(int argc, char *argv[])
break;
default:
usage();
+ free(groups);
return 1;
}
}
@@ -247,7 +248,7 @@ main(int argc, char *argv[])
if(ngroups < 0)
{
perror("getgroups");
- return 1;
+ goto failure;
}
}
else if(argc == 1)
@@ -256,7 +257,7 @@ main(int argc, char *argv[])
if(pw_n == NULL)
{
- return 1;
+ goto failure;
}
pw = *pw_n;
epw = *pw_n;
@@ -271,7 +272,7 @@ main(int argc, char *argv[])
if(ngroups < 0)
{
perror("getgrouplist");
- return 1;
+ goto failure;
}
}
else
@@ -309,10 +310,10 @@ main(int argc, char *argv[])
if(ret < 0)
{
- return 1;
+ goto failure;
}
- return 0;
+ goto done;
}
if(mode == ID_UID)
@@ -342,10 +343,10 @@ main(int argc, char *argv[])
if(ret < 0)
{
- return 1;
+ goto failure;
}
- return 0;
+ goto done;
}
if(mode == ID_GROUPS)
@@ -364,13 +365,13 @@ main(int argc, char *argv[])
goto failure;
}
- return 0;
+ goto done;
}
ret = print_uid("uid", &pw, uid);
if(ret < 0)
{
- return 1;
+ goto failure;
}
if(euid != uid)
@@ -406,14 +407,14 @@ main(int argc, char *argv[])
ret = printf("\n");
if(ret < 0)
{
- return 1;
+ goto failure;
}
+done:
free(groups);
return 0;
failure:
- printf("\n");
free(groups);
return 1;
}