diff options
author | Jo-Philipp Wich <jo@mein.io> | 2024-09-23 16:39:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-23 16:39:42 +0200 |
commit | 6e88c62203fae7cc7d08d9f84058c515192aca0d (patch) | |
tree | a162f6b9c5bb2328fe517ffcc5a255fb06b39415 | |
parent | b610860dd4a0591ff586dd71a50f556a0ddafced (diff) | |
parent | 67cd1232389fa407575b1e130b6b5668b18b0e7f (diff) |
Merge pull request #224 from jow-/lib-fs-readline-leak
fs: fix potential memory leak on i/o errors in .read()
-rw-r--r-- | lib/fs.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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; } @@ -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; } |