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
commit 9eb191edc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 4 deletions

View File

@ -336,8 +336,12 @@ static int create_backup (const char *backup, FILE * fp)
/* FIXME: unlink the backup file? */ /* FIXME: unlink the backup file? */
return -1; return -1;
} }
if ( (fsync (fileno (bkfp)) != 0) if (fsync (fileno (bkfp)) != 0) {
|| (fclose (bkfp) != 0)) { (void) fclose (bkfp);
/* FIXME: unlink the backup file? */
return -1;
}
if (fclose (bkfp) != 0) {
/* FIXME: unlink the backup file? */ /* FIXME: unlink the backup file? */
return -1; return -1;
} }

View File

@ -57,6 +57,7 @@ int add_groups (const char *list)
bool added; bool added;
char *token; char *token;
char buf[1024]; char buf[1024];
int ret;
if (strlen (list) >= sizeof (buf)) { if (strlen (list) >= sizeof (buf)) {
errno = EINVAL; errno = EINVAL;
@ -120,9 +121,12 @@ int add_groups (const char *list)
} }
if (added) { if (added) {
return setgroups ((size_t)ngroups, grouplist); ret = setgroups ((size_t)ngroups, grouplist);
free (grouplist);
return ret;
} }
free (grouplist);
return 0; return 0;
} }
#else /* HAVE_SETGROUPS && !USE_PAM */ #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")); grent = getgr_nam_gid (getdef_str ("TTYGROUP"));
if (NULL != grent) { if (NULL != grent) {
gid = grent->gr_gid; gid = grent->gr_gid;
gr_free (grent);
} else { } else {
gid = info->pw_gid; gid = info->pw_gid;
} }

View File

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

View File

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

View File

@ -62,6 +62,9 @@
if ((NULL != pw) && (pw->pw_uid == ruid)) { if ((NULL != pw) && (pw->pw_uid == ruid)) {
return pw; return pw;
} }
if (NULL != pw) {
pw_free (pw);
}
} }
return xgetpwuid (ruid); 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) { if (check_status (name, task_path+6, uid) != 0) {
(void) closedir (proc); (void) closedir (proc);
(void) closedir (task_dir);
#ifdef ENABLE_SUBIDS #ifdef ENABLE_SUBIDS
sub_uid_close(); sub_uid_close();
#endif #endif

View File

@ -162,8 +162,9 @@ static void check_perms (const struct group *grp,
*/ */
spwd = xgetspnam (pwd->pw_name); spwd = xgetspnam (pwd->pw_name);
if (NULL != spwd) { if (NULL != spwd) {
pwd->pw_passwd = spwd->sp_pwdp; pwd->pw_passwd = xstrdup (spwd->sp_pwdp);
} }
spw_free (spwd);
if ((pwd->pw_passwd[0] == '\0') && (grp->gr_passwd[0] != '\0')) { if ((pwd->pw_passwd[0] == '\0') && (grp->gr_passwd[0] != '\0')) {
needspasswd = true; needspasswd = true;

View File

@ -553,6 +553,11 @@ static char *update_crypt_pw (char *cp)
strcpy (newpw, "!"); strcpy (newpw, "!");
strcat (newpw, cp); strcat (newpw, cp);
#ifndef USE_PAM
if (do_update_pwd) {
free (cp);
}
#endif /* USE_PAM */
cp = newpw; cp = newpw;
} }
return cp; return cp;