summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tcpsrv.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/tcpsrv.c b/tcpsrv.c
index 1f307b7e..85b34947 100644
--- a/tcpsrv.c
+++ b/tcpsrv.c
@@ -309,7 +309,7 @@ static rsRetVal
SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm)
{
DEFiRet;
- tcps_sess_t *pSess;
+ tcps_sess_t *pSess = NULL;
netstrm_t *pNewStrm = NULL;
int iSess = -1;
struct sockaddr_storage *addr;
@@ -356,7 +356,9 @@ SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm)
* means we can finally fill in the session object.
*/
CHKiRet(tcps_sess.SetHost(pSess, fromHostFQDN));
+ fromHostFQDN = NULL; /* we handed this string over */
CHKiRet(tcps_sess.SetHostIP(pSess, fromHostIP));
+ fromHostIP = NULL; /* we handed this string over */
CHKiRet(tcps_sess.SetStrm(pSess, pNewStrm));
pNewStrm = NULL; /* prevent it from being freed in error handler, now done in tcps_sess! */
CHKiRet(tcps_sess.SetMsgIdx(pSess, 0));
@@ -369,14 +371,16 @@ SessAccept(tcpsrv_t *pThis, tcps_sess_t **ppSess, netstrm_t *pStrm)
*ppSess = pSess;
pThis->pSessions[iSess] = pSess;
+ pSess = NULL; /* this is now also handed over */
finalize_it:
if(iRet != RS_RET_OK) {
- if(iSess != -1) {
- if(pThis->pSessions[iSess] != NULL)
- tcps_sess.Destruct(&pThis->pSessions[iSess]);
- }
- iSess = -1; // TODO: change this to be fully iRet compliant ;)
+ if(pSess != NULL)
+ tcps_sess.Destruct(&pSess);
+ if(fromHostFQDN != NULL)
+ free(fromHostFQDN);
+ if(fromHostIP != NULL)
+ free(fromHostIP);
if(pNewStrm != NULL)
netstrm.Destruct(&pNewStrm);
}