mirror of https://github.com/F-Stack/f-stack.git
fix memory leak issue.
This commit is contained in:
parent
df6ad73146
commit
c9f0232b74
|
@ -721,8 +721,7 @@ ff_accept(int s, struct linux_sockaddr * addr,
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct file *fp;
|
struct file *fp;
|
||||||
struct sockaddr bsdaddr;
|
struct sockaddr *pf = NULL;
|
||||||
struct sockaddr *pf = &bsdaddr;
|
|
||||||
socklen_t socklen = sizeof(struct sockaddr);
|
socklen_t socklen = sizeof(struct sockaddr);
|
||||||
|
|
||||||
if ((rc = kern_accept(curthread, s, &pf, &socklen, &fp)))
|
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];
|
rc = curthread->td_retval[0];
|
||||||
fdrop(fp, curthread);
|
fdrop(fp, curthread);
|
||||||
|
|
||||||
if (addr)
|
if (addr && pf)
|
||||||
freebsd2linux_sockaddr(addr, pf);
|
freebsd2linux_sockaddr(addr, pf);
|
||||||
|
|
||||||
if (addrlen)
|
if (addrlen)
|
||||||
*addrlen = socklen;
|
*addrlen = socklen;
|
||||||
|
|
||||||
|
if(pf != NULL)
|
||||||
|
free(pf, M_SONAME);
|
||||||
return (rc);
|
return (rc);
|
||||||
|
|
||||||
kern_fail:
|
kern_fail:
|
||||||
|
if(pf != NULL)
|
||||||
|
free(pf, M_SONAME);
|
||||||
ff_os_errno(rc);
|
ff_os_errno(rc);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
@ -797,17 +801,21 @@ ff_getpeername(int s, struct linux_sockaddr * name,
|
||||||
socklen_t *namelen)
|
socklen_t *namelen)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct sockaddr bsdaddr;
|
struct sockaddr *pf = NULL;
|
||||||
struct sockaddr *pf = &bsdaddr;
|
|
||||||
|
|
||||||
if ((rc = kern_getpeername(curthread, s, &pf, namelen)))
|
if ((rc = kern_getpeername(curthread, s, &pf, namelen)))
|
||||||
goto kern_fail;
|
goto kern_fail;
|
||||||
|
|
||||||
if (name)
|
if (name && pf)
|
||||||
freebsd2linux_sockaddr(name, pf);
|
freebsd2linux_sockaddr(name, pf);
|
||||||
|
|
||||||
|
if(pf != NULL)
|
||||||
|
free(pf, M_SONAME);
|
||||||
return (rc);
|
return (rc);
|
||||||
|
|
||||||
kern_fail:
|
kern_fail:
|
||||||
|
if(pf != NULL)
|
||||||
|
free(pf, M_SONAME);
|
||||||
ff_os_errno(rc);
|
ff_os_errno(rc);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
@ -817,18 +825,21 @@ ff_getsockname(int s, struct linux_sockaddr *name,
|
||||||
socklen_t *namelen)
|
socklen_t *namelen)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct sockaddr bsdaddr;
|
struct sockaddr *pf = NULL;
|
||||||
struct sockaddr *pf = &bsdaddr;
|
|
||||||
|
|
||||||
if ((rc = kern_getsockname(curthread, s, &pf, namelen)))
|
if ((rc = kern_getsockname(curthread, s, &pf, namelen)))
|
||||||
goto kern_fail;
|
goto kern_fail;
|
||||||
|
|
||||||
if (name)
|
if (name && pf)
|
||||||
freebsd2linux_sockaddr(name, pf);
|
freebsd2linux_sockaddr(name, pf);
|
||||||
|
|
||||||
|
if(pf != NULL)
|
||||||
|
free(pf, M_SONAME);
|
||||||
return (rc);
|
return (rc);
|
||||||
|
|
||||||
kern_fail:
|
kern_fail:
|
||||||
|
if(pf != NULL)
|
||||||
|
free(pf, M_SONAME);
|
||||||
ff_os_errno(rc);
|
ff_os_errno(rc);
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue