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.
This commit is contained in:
Josef Söntgen 2013-12-10 13:46:15 +01:00 committed by Norman Feske
parent f71e38702f
commit 2e6255d1cf
1 changed files with 6 additions and 3 deletions

View File

@ -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) {