Fix several related coverity issues:
Make sure to always free shortopts and lopts when returning. Fix minor logic bug to guard against NULLs properly. CID: 1403654, 1403656, 1403658
This commit is contained in:
parent
2b3ac10a27
commit
ae5f2ca7b9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350309
@ -155,7 +155,7 @@ find_long(struct option *lopts, int ch)
|
|||||||
|
|
||||||
for (i = 0; lopts[i].val != ch && lopts[i].name != NULL; i++)
|
for (i = 0; lopts[i].val != ch && lopts[i].name != NULL; i++)
|
||||||
continue;
|
continue;
|
||||||
return i;
|
return (i);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -251,6 +251,8 @@ arg_parse(int argc, char * const * argv, const struct cmd *f)
|
|||||||
if (optind >= argc) {
|
if (optind >= argc) {
|
||||||
fprintf(stderr, "Missing arg %s\n", args->descr);
|
fprintf(stderr, "Missing arg %s\n", args->descr);
|
||||||
arg_help(argc, argv, f);
|
arg_help(argc, argv, f);
|
||||||
|
free(lopts);
|
||||||
|
free(shortopts);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
*(char **)args->ptr = argv[optind++];
|
*(char **)args->ptr = argv[optind++];
|
||||||
@ -258,10 +260,12 @@ arg_parse(int argc, char * const * argv, const struct cmd *f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(lopts);
|
free(lopts);
|
||||||
|
free(shortopts);
|
||||||
return (0);
|
return (0);
|
||||||
bad_arg:
|
bad_arg:
|
||||||
fprintf(stderr, "Bad value to --%s: %s\n", opts[idx].long_arg, optarg);
|
fprintf(stderr, "Bad value to --%s: %s\n", opts[idx].long_arg, optarg);
|
||||||
free(lopts);
|
free(lopts);
|
||||||
|
free(shortopts);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -465,7 +465,7 @@ logpage(const struct cmd *f, int argc, char *argv[])
|
|||||||
* unless the vendors match.
|
* unless the vendors match.
|
||||||
*/
|
*/
|
||||||
SLIST_FOREACH(lpf, &logpages, link) {
|
SLIST_FOREACH(lpf, &logpages, link) {
|
||||||
if (lpf->vendor != NULL && vendor != NULL &&
|
if (lpf->vendor == NULL || vendor == NULL ||
|
||||||
strcmp(lpf->vendor, vendor) != 0)
|
strcmp(lpf->vendor, vendor) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (opt.page != lpf->log_page)
|
if (opt.page != lpf->log_page)
|
||||||
|
Loading…
Reference in New Issue
Block a user