netutils/ftpc: Fix some memory leaks

This commit is contained in:
Boris Astardzhiev 2017-07-27 07:29:06 -06:00 committed by Gregory Nutt
parent 19acc8ad4e
commit 158cbeb151
3 changed files with 15 additions and 2 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* apps/netutils/ftpc/ftpc_chdir.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2011, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -86,6 +86,13 @@ int ftpc_chdir(SESSION handle, FAR const char *path)
return ret;
}
/* Free any previous setting and set the new working directory */
if (session->currdir != NULL)
{
free(session->currdir);
}
session->currdir = ftpc_rpwd(handle);
return OK;
}

View File

@ -105,7 +105,7 @@ SESSION ftpc_connect(FAR struct ftpc_connect_s *server)
*/
session->homeldir = strdup(ftpc_lpwd());
/* session->curldir = strdup(sssion->homeldir); */
/* session->curldir = strdup(session->homeldir); */
/* Create up a timer to prevent hangs */
@ -123,6 +123,11 @@ SESSION ftpc_connect(FAR struct ftpc_connect_s *server)
return (SESSION)session;
errout_with_alloc:
if (session->homeldir != NULL)
{
free(session->homeldir);
}
free(session);
errout:
return NULL;

View File

@ -93,6 +93,7 @@ void ftpc_disconnect(SESSION handle)
free(session->pwd);
free(session->initrdir);
free(session->homerdir);
free(session->homeldir);
free(session->currdir);
/* Then destroy the session */