Skip to content

Commit

Permalink
Merge pull request #224 from jow-/lib-fs-readline-leak
Browse files Browse the repository at this point in the history
fs: fix potential memory leak on i/o errors in .read()
  • Loading branch information
jow- authored Sep 23, 2024
2 parents b610860 + 67cd123 commit 6e88c62
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ uc_fs_read_common(uc_vm_t *vm, size_t nargs, const char *type)
if (llen == 4 && !strcmp(lstr, "line")) {
llen = getline(&p, &rlen, *fp);

if (llen == -1)
if (llen == -1) {
free(p);
err_return(errno);
}

len = (size_t)llen;
}
Expand All @@ -158,8 +160,10 @@ uc_fs_read_common(uc_vm_t *vm, size_t nargs, const char *type)
else if (llen == 1) {
llen = getdelim(&p, &rlen, *lstr, *fp);

if (llen == -1)
if (llen == -1) {
free(p);
err_return(errno);
}

len = (size_t)llen;
}
Expand Down

0 comments on commit 6e88c62

Please sign in to comment.