pmap: Plug memory leak in range_arguments().
Also, simplify the code slightly (but functionally equivalent). Check the return value of xstrdup() only once (yes, it can return NULL).
This commit is contained in:
parent
14758ebc8f
commit
db2f011895
23
pmap.c
23
pmap.c
@ -744,26 +744,29 @@ static int one_proc(proc_t * p)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void range_arguments(char *optarg)
|
||||
static void range_arguments(const char *optarg)
|
||||
{
|
||||
char *arg1;
|
||||
char *arg2;
|
||||
|
||||
arg1 = xstrdup(optarg);
|
||||
char *const copy = xstrdup(optarg);
|
||||
if (!copy)
|
||||
goto fail;
|
||||
arg1 = copy;
|
||||
arg2 = strchr(arg1, ',');
|
||||
if (arg2)
|
||||
*arg2 = '\0';
|
||||
if (arg2)
|
||||
++arg2;
|
||||
*arg2++ = '\0';
|
||||
else
|
||||
arg2 = arg1;
|
||||
if (arg1 && *arg1)
|
||||
if (*arg1)
|
||||
range_low = STRTOUKL(arg1, &arg1, 16);
|
||||
if (*arg2)
|
||||
range_high = STRTOUKL(arg2, &arg2, 16);
|
||||
if (arg1 && (*arg1 || *arg2))
|
||||
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"),
|
||||
optarg);
|
||||
if (*arg1 || *arg2)
|
||||
goto fail;
|
||||
free(copy);
|
||||
return;
|
||||
fail:
|
||||
xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"), optarg);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user