top: avoid unrecognized 'Inspect' entries memory leaks
Upon startup there exists the potential for some minor memory leakage should some rcfile 'Inspect' entries be invalid. By delaying any malloc/strdup until after the entries are completely validated we will prevent that. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
11b87c73ed
commit
40dbd50056
14
top/top.c
14
top/top.c
@ -3336,7 +3336,7 @@ static int config_insp (FILE *fp, char *buf, size_t size) {
|
||||
#define nxtLINE { buf[0] = '\0'; continue; }
|
||||
size_t lraw = strlen(Inspect.raw) +1;
|
||||
int n, x;
|
||||
char *s;
|
||||
char *s1, *s2, *s3;
|
||||
|
||||
if (i < 0 || (size_t)i >= INT_MAX / sizeof(struct I_ent)) break;
|
||||
if (lraw >= INT_MAX - size) break;
|
||||
@ -3357,12 +3357,9 @@ static int config_insp (FILE *fp, char *buf, size_t size) {
|
||||
Rc_questions = 1;
|
||||
}
|
||||
}
|
||||
if (!(s = strtok(buf, "\t\n"))) { Rc_questions = 1; nxtLINE; }
|
||||
iT(type) = alloc_s(s);
|
||||
if (!(s = strtok(NULL, "\t\n"))) { Rc_questions = 1; nxtLINE; }
|
||||
iT(name) = alloc_s(s);
|
||||
if (!(s = strtok(NULL, "\t\n"))) { Rc_questions = 1; nxtLINE; }
|
||||
iT(fmts) = alloc_s(s);
|
||||
if (!(s1 = strtok(buf, "\t\n"))) { Rc_questions = 1; nxtLINE; }
|
||||
if (!(s2 = strtok(NULL, "\t\n"))) { Rc_questions = 1; nxtLINE; }
|
||||
if (!(s3 = strtok(NULL, "\t\n"))) { Rc_questions = 1; nxtLINE; }
|
||||
|
||||
switch (toupper(buf[0])) {
|
||||
case 'F':
|
||||
@ -3375,6 +3372,9 @@ static int config_insp (FILE *fp, char *buf, size_t size) {
|
||||
Rc_questions = 1;
|
||||
nxtLINE;
|
||||
}
|
||||
iT(type) = alloc_s(s1);
|
||||
iT(name) = alloc_s(s2);
|
||||
iT(fmts) = alloc_s(s3);
|
||||
iT(farg) = (strstr(iT(fmts), "%d")) ? 1 : 0;
|
||||
iT(fstr) = alloc_c(FNDBUFSIZ);
|
||||
iT(flen) = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user