From 2e6255d1cfdfa35866c2e7c1f87f45b73211cfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 10 Dec 2013 13:46:15 +0100 Subject: [PATCH] libc_fs: fix potential memory leak in symlink() Free always the file descriptor and plugin context, return the appropriate value to the caller and only in the error case set errno. Fixes #1009. --- libports/src/lib/libc_fs/plugin.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libports/src/lib/libc_fs/plugin.cc b/libports/src/lib/libc_fs/plugin.cc index 4f1f9742d3..b69dcafa79 100644 --- a/libports/src/lib/libc_fs/plugin.cc +++ b/libports/src/lib/libc_fs/plugin.cc @@ -722,13 +722,16 @@ class Plugin : public Libc::Plugin Libc::File_descriptor *fd = Libc::file_descriptor_allocator()->alloc(this, context); - if (write(fd, oldpath, strlen(oldpath) + 1) == -1) { + ssize_t res = write(fd, oldpath, strlen(oldpath) + 1); + + Libc::file_descriptor_allocator()->free(fd); + destroy(Genode::env()->heap(), context); + + if (res == -1) { errno = EIO; return -1; } - close(fd); - return 0; } catch (File_system::Lookup_failed) {