Skip to content

Commit

Permalink
fix memory leak issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
derness committed Jun 7, 2017
1 parent df6ad73 commit c9f0232
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/ff_syscall_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit c9f0232

Please sign in to comment.