mirror of
https://github.com/apache/nuttx.git
synced 2026-05-29 20:56:47 +08:00
execl(): Don't allocate or free and argv[] list if there are not arguments
This commit is contained in:
@@ -124,7 +124,7 @@
|
|||||||
|
|
||||||
int execl(FAR const char *path, ...)
|
int execl(FAR const char *path, ...)
|
||||||
{
|
{
|
||||||
FAR char **argv;
|
FAR char **argv = (FAR char **)NULL;
|
||||||
size_t nargs;
|
size_t nargs;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int argc;
|
int argc;
|
||||||
@@ -152,6 +152,8 @@ int execl(FAR const char *path, ...)
|
|||||||
|
|
||||||
/* Allocate a temporary argv[] array */
|
/* Allocate a temporary argv[] array */
|
||||||
|
|
||||||
|
if (nargs > 0)
|
||||||
|
{
|
||||||
argv = (FAR char **)malloc((nargs + 1) * sizeof(FAR char *));
|
argv = (FAR char **)malloc((nargs + 1) * sizeof(FAR char *));
|
||||||
if (argv = (FAR char **)NULL)
|
if (argv = (FAR char **)NULL)
|
||||||
{
|
{
|
||||||
@@ -169,14 +171,19 @@ int execl(FAR const char *path, ...)
|
|||||||
|
|
||||||
argv[nargs] = NULL;
|
argv[nargs] = NULL;
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
/* Then let execv() do the real work */
|
/* Then let execv() do the real work */
|
||||||
|
|
||||||
ret = execv(path, (char * const *)&argv);
|
ret = execv(path, (FAR char * const *)argv);
|
||||||
|
|
||||||
/* Free the allocated argv[] list */
|
/* Free the allocated argv[] list */
|
||||||
|
|
||||||
|
if (argv)
|
||||||
|
{
|
||||||
free(argv);
|
free(argv);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user