Fix a memleak on invalid command line options
The OS will clean it up yes, but in the meanwhile ASAN (when enabled) blew up on your face and scared you silly. Use the opportunity to add a test for a test on invalid option.
This commit is contained in:
parent
126b7ab7af
commit
1825dbf824
|
@ -292,7 +292,7 @@ rpmcliFini(poptContext optCon)
|
|||
poptContext
|
||||
rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
|
||||
{
|
||||
poptContext optCon;
|
||||
poptContext optCon = NULL;
|
||||
int rc;
|
||||
const char *ctx, *execPath;
|
||||
|
||||
|
@ -332,14 +332,14 @@ rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
|
|||
while ((rc = poptGetNextOpt(optCon)) > 0) {
|
||||
fprintf(stderr, _("%s: option table misconfigured (%d)\n"),
|
||||
xgetprogname(), rc);
|
||||
exit(EXIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (rc < -1) {
|
||||
fprintf(stderr, "%s: %s: %s\n", xgetprogname(),
|
||||
poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
|
||||
poptStrerror(rc));
|
||||
exit(EXIT_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* Read rpm configuration (if not already read). */
|
||||
|
@ -351,4 +351,9 @@ rpmcliInit(int argc, char *const argv[], struct poptOption * optionsTable)
|
|||
}
|
||||
|
||||
return optCon;
|
||||
|
||||
err:
|
||||
poptFreeContext(optCon);
|
||||
exit(EXIT_FAILURE);
|
||||
return NULL; /* not reached */
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ RPMTEST_CHECK([runroot rpm --version],[0],
|
|||
])
|
||||
RPMTEST_CLEANUP
|
||||
|
||||
|
||||
# ------------------------------
|
||||
AT_SETUP([rpmbuild --version])
|
||||
AT_KEYWORDS([basic])
|
||||
|
@ -35,6 +34,15 @@ RPMTEST_CHECK([runroot rpmbuild --version],[0],
|
|||
])
|
||||
RPMTEST_CLEANUP
|
||||
|
||||
AT_SETUP([rpm invalid option])
|
||||
AT_KEYWORDS([basic])
|
||||
RPMTEST_CHECK([runroot rpm --badopt],
|
||||
[1],
|
||||
[],
|
||||
[rpm: --badopt: unknown option
|
||||
])
|
||||
RPMTEST_CLEANUP
|
||||
|
||||
# Check that libtool versioning matches expectations, it's easy to screw up.
|
||||
AT_SETUP([rpm library version])
|
||||
AT_KEYWORDS([basic])
|
||||
|
|
Loading…
Reference in New Issue