Skip to content

Commit 8d7d93d

Browse files
Correct some error handling path in libc_emcc (#4803)
1 parent d58586a commit 8d7d93d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/iwasm/libraries/libc-emcc/libc_emcc_wrapper.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,21 @@ mmap_wrapper(wasm_exec_env_t exec_env, void *addr, int length, int prot,
245245
if (buf_offset == 0)
246246
return -1;
247247

248-
if (fd <= 0)
248+
if (fd <= 0) {
249+
module_free((uint64)buf_offset);
249250
return -1;
251+
}
250252

251-
if (lseek(fd, offset, SEEK_SET) == -1)
253+
if (lseek(fd, offset, SEEK_SET) == -1) {
254+
module_free((uint64)buf_offset);
252255
return -1;
256+
}
253257

254258
size_read = read(fd, buf, length);
255-
(void)size_read;
259+
if (size_read < 0) {
260+
module_free((uint64)buf_offset);
261+
return -1;
262+
}
256263
return buf_offset;
257264
}
258265

0 commit comments

Comments
 (0)