From c9f0232b740648140438657293896cd7ad74e837 Mon Sep 17 00:00:00 2001 From: derness Date: Wed, 7 Jun 2017 13:18:11 +0800 Subject: [PATCH] fix memory leak issue. --- lib/ff_syscall_wrapper.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/ff_syscall_wrapper.c b/lib/ff_syscall_wrapper.c index 89e606e82..da3f4d3e5 100644 --- a/lib/ff_syscall_wrapper.c +++ b/lib/ff_syscall_wrapper.c @@ -721,8 +721,7 @@ ff_accept(int s, struct linux_sockaddr * addr, { int rc; struct file *fp; - struct sockaddr bsdaddr; - struct sockaddr *pf = &bsdaddr; + struct sockaddr *pf = NULL; socklen_t socklen = sizeof(struct sockaddr); if ((rc = kern_accept(curthread, s, &pf, &socklen, &fp))) @@ -731,14 +730,19 @@ ff_accept(int s, struct linux_sockaddr * addr, rc = curthread->td_retval[0]; fdrop(fp, curthread); - if (addr) + if (addr && pf) freebsd2linux_sockaddr(addr, pf); if (addrlen) *addrlen = socklen; - + + if(pf != NULL) + free(pf, M_SONAME); return (rc); + kern_fail: + if(pf != NULL) + free(pf, M_SONAME); ff_os_errno(rc); return (-1); } @@ -797,17 +801,21 @@ ff_getpeername(int s, struct linux_sockaddr * name, socklen_t *namelen) { int rc; - struct sockaddr bsdaddr; - struct sockaddr *pf = &bsdaddr; + struct sockaddr *pf = NULL; if ((rc = kern_getpeername(curthread, s, &pf, namelen))) goto kern_fail; - if (name) + if (name && pf) freebsd2linux_sockaddr(name, pf); + if(pf != NULL) + free(pf, M_SONAME); return (rc); + kern_fail: + if(pf != NULL) + free(pf, M_SONAME); ff_os_errno(rc); return (-1); } @@ -817,18 +825,21 @@ ff_getsockname(int s, struct linux_sockaddr *name, socklen_t *namelen) { int rc; - struct sockaddr bsdaddr; - struct sockaddr *pf = &bsdaddr; + struct sockaddr *pf = NULL; if ((rc = kern_getsockname(curthread, s, &pf, namelen))) goto kern_fail; - if (name) + if (name && pf) freebsd2linux_sockaddr(name, pf); + if(pf != NULL) + free(pf, M_SONAME); return (rc); kern_fail: + if(pf != NULL) + free(pf, M_SONAME); ff_os_errno(rc); return (-1); }