forked from Imagelibrary/rtems
2010-08-28 Joel Sherrill <joel.sherrill@oarcorp.com>
PR 1694/shell * libmisc/shell/main_setenv.c: Address memory leak identified by Coverity.
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
2010-08-28 Joel Sherrill <joel.sherrill@oarcorp.com>
|
||||||
|
|
||||||
|
PR 1694/shell
|
||||||
|
* libmisc/shell/main_setenv.c: Address memory leak identified by
|
||||||
|
Coverity.
|
||||||
|
|
||||||
2010-08-28 Joel Sherrill <joel.sherrilL@OARcorp.com>
|
2010-08-28 Joel Sherrill <joel.sherrilL@OARcorp.com>
|
||||||
|
|
||||||
* libfs/src/pipe/pipe.c: Remove unreachable line flagged by Coverity as
|
* libfs/src/pipe/pipe.c: Remove unreachable line flagged by Coverity as
|
||||||
|
|||||||
@@ -24,44 +24,41 @@ int rtems_shell_main_setenv(int argc, char *argv[])
|
|||||||
int arg;
|
int arg;
|
||||||
char* p;
|
char* p;
|
||||||
|
|
||||||
if (argc <= 2)
|
if (argc <= 2) {
|
||||||
{
|
printf("error: no variable or string\n");
|
||||||
printf ("error: no variable or string\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
env = argv[1];
|
env = argv[1];
|
||||||
|
|
||||||
for (arg = 2; arg < argc; arg++)
|
for (arg = 2; arg < argc; arg++)
|
||||||
len += strlen (argv[arg]);
|
len += strlen(argv[arg]);
|
||||||
|
|
||||||
len += argc - 2 - 1;
|
len += argc - 2 - 1;
|
||||||
|
|
||||||
string = malloc (len + 1);
|
string = malloc(len + 1);
|
||||||
|
|
||||||
if (!string)
|
if (!string) {
|
||||||
{
|
printf("error: no memory\n");
|
||||||
printf ("error: no memory\n");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (arg = 2, p = string; arg < argc; arg++)
|
for (arg = 2, p = string; arg < argc; arg++) {
|
||||||
{
|
strcpy(p, argv[arg]);
|
||||||
strcpy (p, argv[arg]);
|
p += strlen(argv[arg]);
|
||||||
p += strlen (argv[arg]);
|
if (arg < (argc - 1)) {
|
||||||
if (arg < (argc - 1))
|
|
||||||
{
|
|
||||||
*p = ' ';
|
*p = ' ';
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setenv (env, string, 1) < 0)
|
if (setenv(env, string, 1) < 0) {
|
||||||
{
|
printf( "error: %s\n", strerror(errno) );
|
||||||
printf ("error: %s\n", strerror (errno));
|
free( string );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free( string );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user