Merge pull request #359 from ikerexxe/rest_resource_leak

Fix covscan RESOURCE_LEAK
This commit is contained in:
Serge Hallyn
2021-06-24 13:14:15 -05:00
committed by GitHub
10 changed files with 33 additions and 4 deletions

View File

@ -57,6 +57,7 @@ int add_groups (const char *list)
bool added;
char *token;
char buf[1024];
int ret;
if (strlen (list) >= sizeof (buf)) {
errno = EINVAL;
@ -120,9 +121,12 @@ int add_groups (const char *list)
}
if (added) {
return setgroups ((size_t)ngroups, grouplist);
ret = setgroups ((size_t)ngroups, grouplist);
free (grouplist);
return ret;
}
free (grouplist);
return 0;
}
#else /* HAVE_SETGROUPS && !USE_PAM */

View File

@ -62,6 +62,7 @@ void chown_tty (const struct passwd *info)
grent = getgr_nam_gid (getdef_str ("TTYGROUP"));
if (NULL != grent) {
gid = grent->gr_gid;
gr_free (grent);
} else {
gid = info->pw_gid;
}

View File

@ -745,6 +745,7 @@ static int copy_file (const char *src, const char *dst,
}
#ifdef WITH_SELINUX
if (set_selinux_file_context (dst, S_IFREG) != 0) {
(void) close (ifd);
return -1;
}
#endif /* WITH_SELINUX */
@ -771,12 +772,16 @@ static int copy_file (const char *src, const char *dst,
&& (errno != 0))
#endif /* WITH_ATTR */
) {
if (ofd >= 0) {
(void) close (ofd);
}
(void) close (ifd);
return -1;
}
while ((cnt = read (ifd, buf, sizeof buf)) > 0) {
if (write (ofd, buf, (size_t)cnt) != cnt) {
(void) close (ofd);
(void) close (ifd);
return -1;
}
@ -786,6 +791,7 @@ static int copy_file (const char *src, const char *dst,
#ifdef HAVE_FUTIMES
if (futimes (ofd, mt) != 0) {
(void) close (ofd);
return -1;
}
#endif /* HAVE_FUTIMES */

View File

@ -241,4 +241,5 @@ void write_mapping(int proc_dir_fd, int ranges, struct map_range *mappings,
exit(EXIT_FAILURE);
}
close(fd);
free(buf);
}

View File

@ -241,6 +241,7 @@ bool is_on_list (char *const *list, const char *member)
if ('\0' == *members) {
*array = (char *) 0;
free (members);
return array;
}
@ -262,6 +263,8 @@ bool is_on_list (char *const *list, const char *member)
}
}
free (members);
/*
* Return the new array of pointers
*/

View File

@ -62,6 +62,9 @@
if ((NULL != pw) && (pw->pw_uid == ruid)) {
return pw;
}
if (NULL != pw) {
pw_free (pw);
}
}
return xgetpwuid (ruid);

View File

@ -269,6 +269,7 @@ static int user_busy_processes (const char *name, uid_t uid)
}
if (check_status (name, task_path+6, uid) != 0) {
(void) closedir (proc);
(void) closedir (task_dir);
#ifdef ENABLE_SUBIDS
sub_uid_close();
#endif