Commit 94857959 authored by Jan Kiszka's avatar Jan Kiszka

copperplate: Handle errors properly in get_session_label

strdup may fail. And if we fail otherwise later, session will leak.
The second issue was reported by clang-9 scan-build.
Signed-off-by: Jan Kiszka's avatarJan Kiszka <jan.kiszka@siemens.com>
parent db0a60a2
...@@ -155,6 +155,8 @@ static int get_session_label(const char *optarg) ...@@ -155,6 +155,8 @@ static int get_session_label(const char *optarg)
int ret; int ret;
session = strdup(optarg); session = strdup(optarg);
if (!session)
return -ENOMEM;
grpname = strrchr(session, '/'); grpname = strrchr(session, '/');
if (grpname == NULL) if (grpname == NULL)
goto no_group; goto no_group;
...@@ -163,8 +165,10 @@ static int get_session_label(const char *optarg) ...@@ -163,8 +165,10 @@ static int get_session_label(const char *optarg)
if (isdigit(*grpname)) { if (isdigit(*grpname)) {
gid = (gid_t)strtol(grpname, &p, 10); gid = (gid_t)strtol(grpname, &p, 10);
if (*p) if (*p) {
free(session);
return -EINVAL; return -EINVAL;
}
errno = 0; errno = 0;
grp = getgrgid(gid); grp = getgrgid(gid);
} else { } else {
...@@ -175,6 +179,7 @@ static int get_session_label(const char *optarg) ...@@ -175,6 +179,7 @@ static int get_session_label(const char *optarg)
if (grp == NULL) { if (grp == NULL) {
ret = errno ? -errno : -EINVAL; ret = errno ? -errno : -EINVAL;
warning("invalid group %s", grpname); warning("invalid group %s", grpname);
free(session);
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment