mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
341114: Coverity 517 SECU_ParseCommandLine leaks optstate. r=nelson
This commit is contained in:
parent
2e23193e89
commit
c89f85e085
@ -3021,7 +3021,7 @@ SECU_ParseCommandLine(int argc, char **argv, char *progName, secuCommand *cmd)
|
||||
char *optstring;
|
||||
int i, j;
|
||||
|
||||
optstring = (char *)malloc(cmd->numCommands + 2*cmd->numOptions);
|
||||
optstring = (char *)PORT_Alloc(cmd->numCommands + 2*cmd->numOptions);
|
||||
j = 0;
|
||||
|
||||
for (i=0; i<cmd->numCommands; i++) {
|
||||
@ -3034,7 +3034,10 @@ SECU_ParseCommandLine(int argc, char **argv, char *progName, secuCommand *cmd)
|
||||
}
|
||||
optstring[j] = '\0';
|
||||
optstate = PL_CreateOptState(argc, argv, optstring);
|
||||
|
||||
if (!optstate) {
|
||||
PORT_Free(optstring);
|
||||
return SECFailure;
|
||||
}
|
||||
/* Parse command line arguments */
|
||||
while ((status = PL_GetNextOpt(optstate)) == PL_OPT_OK) {
|
||||
|
||||
@ -3064,16 +3067,23 @@ SECU_ParseCommandLine(int argc, char **argv, char *progName, secuCommand *cmd)
|
||||
if (optstate->value) {
|
||||
cmd->options[i].arg = (char *)optstate->value;
|
||||
} else if (cmd->options[i].needsArg) {
|
||||
return SECFailure;
|
||||
}
|
||||
status = PL_OPT_BAD;
|
||||
goto loser;
|
||||
}
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
return SECFailure;
|
||||
if (!found) {
|
||||
status = PL_OPT_BAD;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
loser:
|
||||
PL_DestroyOptState(optstate);
|
||||
PORT_Free(optstring);
|
||||
if (status == PL_OPT_BAD)
|
||||
return SECFailure;
|
||||
return SECSuccess;
|
||||
|
Loading…
Reference in New Issue
Block a user