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:
Joel Sherrill
2010-08-28 20:10:00 +00:00
parent c188f8e7f2
commit 8cb97f594f
2 changed files with 20 additions and 17 deletions

View File

@@ -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>
* libfs/src/pipe/pipe.c: Remove unreachable line flagged by Coverity as

View File

@@ -24,44 +24,41 @@ int rtems_shell_main_setenv(int argc, char *argv[])
int arg;
char* p;
if (argc <= 2)
{
printf ("error: no variable or string\n");
if (argc <= 2) {
printf("error: no variable or string\n");
return 1;
}
env = argv[1];
for (arg = 2; arg < argc; arg++)
len += strlen (argv[arg]);
len += strlen(argv[arg]);
len += argc - 2 - 1;
string = malloc (len + 1);
string = malloc(len + 1);
if (!string)
{
printf ("error: no memory\n");
if (!string) {
printf("error: no memory\n");
return 1;
}
for (arg = 2, p = string; arg < argc; arg++)
{
strcpy (p, argv[arg]);
p += strlen (argv[arg]);
if (arg < (argc - 1))
{
for (arg = 2, p = string; arg < argc; arg++) {
strcpy(p, argv[arg]);
p += strlen(argv[arg]);
if (arg < (argc - 1)) {
*p = ' ';
p++;
}
}
if (setenv (env, string, 1) < 0)
{
printf ("error: %s\n", strerror (errno));
if (setenv(env, string, 1) < 0) {
printf( "error: %s\n", strerror(errno) );
free( string );
return 1;
}
free( string );
return 0;
}