This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Plug a couple of memory leaks
- From: Emilio Pozuelo Monfort <pochu27 at gmail dot com>
- To: libc-alpha at sources dot redhat dot com
- Cc: Roland McGrath <roland at gnu dot org>
- Date: Wed, 21 Jul 2010 00:29:33 +0200
- Subject: [PATCH] Plug a couple of memory leaks
Hi,
This patch fixes a couple of leaks in sendmsg(). I was not sure whether to add
an out: label at the end of the function (where it deallocates 'data') and goto
there in both cases, but it calls __hurd_sockfail() there which I'm not sure is
correct when returning from e.g. __file_name_lookup (which is not a socket
syscall, although we're in sendmsg() which is).
Also, if calling __hurd_sockfail() after __ifsock_getsockaddr() is fine, we
would need to call __hurd_fail() before, since __hurd_sockfail() doesn't call
it. Is there a reason why it doesn't?
Finally, I'm curious at why the prototype is __libc_sendmsg and not just
__sendmsg. If there is a file explaining all this magic, just point me to it and
I'll be happy to read it.
Thanks,
Emilio
---
sysdeps/mach/hurd/sendmsg.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
2010-06-02 Emilio Pozuelo Monfort <pochu27@gmail.com>
* sysdeps/mach/hurd/sendmsg.c (__libc_sendmsg): Fix memory leaks.
diff --git a/sysdeps/mach/hurd/sendmsg.c b/sysdeps/mach/hurd/sendmsg.c
index a9d1c8c..118fd59 100644
--- a/sysdeps/mach/hurd/sendmsg.c
+++ b/sysdeps/mach/hurd/sendmsg.c
@@ -109,14 +109,22 @@ __libc_sendmsg (int fd, const struct msghdr *message, int
flags)
and talk to it with the ifsock protocol. */
file_t file = __file_name_lookup (addr->sun_path, 0, 0);
if (file == MACH_PORT_NULL)
- return -1;
+ {
+ if (dealloc)
+ __vm_deallocate (__mach_task_self (), data.addr, len);
+ return -1;
+ }
err = __ifsock_getsockaddr (file, &aport);
__mach_port_deallocate (__mach_task_self (), file);
if (err == MIG_BAD_ID || err == EOPNOTSUPP)
/* The file did not grok the ifsock protocol. */
err = ENOTSOCK;
if (err)
- return __hurd_fail (err);
+ {
+ if (dealloc)
+ __vm_deallocate (__mach_task_self (), data.addr, len);
+ return __hurd_fail (err);
+ }
}
else
err = EIEIO;
--
1.7.1