Skip to content

Commit

Permalink
libmount: deallocate on /proc/swaps parse error
Browse files Browse the repository at this point in the history
Addresses: #596
Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information
karelzak committed Mar 20, 2018
1 parent 4c9e4ce commit b25f3c1
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions libmount/src/tab_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ static int mnt_parse_mountinfo_line(struct libmnt_fs *fs, char *s)
fs->flags |= MNT_FS_KERNEL;
fs->devno = makedev(maj, min);

/* remove "(deleted)" suffix */
/* remove "\040(deleted)" suffix */
sz = strlen(fs->target);
if (sz > PATH_DELETED_SUFFIX_SZ) {
char *ptr = fs->target + (sz - PATH_DELETED_SUFFIX_SZ);
Expand Down Expand Up @@ -318,25 +318,26 @@ static int mnt_parse_swaps_line(struct libmnt_fs *fs, char *s)
fs->size = fsz;
fs->usedsize = usz;

unmangle_string(src);

/* remove "(deleted)" suffix */
/* remove "\040(deleted)" suffix */
sz = strlen(src);
if (sz > PATH_DELETED_SUFFIX_SZ) {
char *p = src + (sz - PATH_DELETED_SUFFIX_SZ);
if (strcmp(p, PATH_DELETED_SUFFIX) == 0)
*p = '\0';
}

unmangle_string(src);

rc = mnt_fs_set_source(fs, src);
if (!rc)
mnt_fs_set_fstype(fs, "swap");
free(src);
} else {
DBG(TAB, ul_debug("tab parse error: [sscanf rc=%d]: '%s'", rc, s));
rc = -EINVAL;
}

free(src);

return rc;
}

Expand Down

0 comments on commit b25f3c1

Please sign in to comment.