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 * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * 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; return ret;
} }
/* Free any previous setting and set the new working directory */
if (session->currdir != NULL)
{
free(session->currdir);
}
session->currdir = ftpc_rpwd(handle); session->currdir = ftpc_rpwd(handle);
return OK; return OK;
} }

View File

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

View File

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