summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2011-05-30 10:44:43 +0300
committerPanu Matilainen <pmatilai@redhat.com>2011-05-30 10:44:43 +0300
commita25c3c7bac95ab7eb55f0ecf0b8793d8da341611 (patch)
treef9b1f4278d4c3745d3954aede16fa72bdc6aeee1 /tools
parent5b2c322887ee2309ce7bd7fe2c055e0968225eee (diff)
downloadrpm-a25c3c7bac95ab7eb55f0ecf0b8793d8da341611.tar.gz
rpm-a25c3c7bac95ab7eb55f0ecf0b8793d8da341611.tar.bz2
rpm-a25c3c7bac95ab7eb55f0ecf0b8793d8da341611.zip
Spring-cleaning for rpmdeps
- Depgen helpers take nno args, their input comes from stdin. Eliminates popt vs ARGV_t mismatch which would've caused us to blow up if it weren't for a memleak on the generated argv. - Another memleak on the file classifier in case rpmfcClassify() or rpmfcApply() fails - just free all allocated resources at exit. - Remove fluff: fgets() is guaranteed to \0-terminate non-NULL returns, eliminate unused/useless variables - Fixup indentation where busted
Diffstat (limited to 'tools')
-rw-r--r--tools/rpmdeps.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/tools/rpmdeps.c b/tools/rpmdeps.c
index 438209c85..6b0b5279a 100644
--- a/tools/rpmdeps.c
+++ b/tools/rpmdeps.c
@@ -45,12 +45,11 @@ static struct poptOption optionsTable[] = {
int
main(int argc, char *argv[])
{
- poptContext optCon;
+ poptContext optCon = NULL;
ARGV_t av = NULL;
- rpmfc fc;
- int ac = 0;
+ rpmfc fc = NULL;
int ec = 1;
-char buf[BUFSIZ];
+ char buf[BUFSIZ];
if ((progname = strrchr(argv[0], '/')) != NULL)
progname++;
@@ -61,45 +60,33 @@ char buf[BUFSIZ];
if (optCon == NULL)
goto exit;
- av = (ARGV_t) poptGetArgs(optCon);
- ac = argvCount(av);
-
- if (ac == 0) {
- char * b, * be;
- av = NULL;
- while ((b = fgets(buf, sizeof(buf), stdin)) != NULL) {
- buf[sizeof(buf)-1] = '\0';
- be = b + strlen(buf) - 1;
- while (strchr("\r\n", *be) != NULL)
- *be-- = '\0';
- argvAdd(&av, b);
- }
- ac = argvCount(av);
+ while (fgets(buf, sizeof(buf), stdin) != NULL) {
+ char *be = buf + strlen(buf) - 1;
+ while (strchr("\r\n", *be) != NULL)
+ *be-- = '\0';
+ argvAdd(&av, buf);
}
-
/* Make sure file names are sorted. */
argvSort(av, NULL);
-
/* Build file/package class and dependency dictionaries. */
fc = rpmfcCreate(getenv("RPM_BUILD_ROOT"), 0);
if (rpmfcClassify(fc, av, NULL) || rpmfcApply(fc))
goto exit;
-if (_rpmfc_debug) {
-rpmfcPrint(buf, fc, NULL);
-}
+ if (_rpmfc_debug)
+ rpmfcPrint(buf, fc, NULL);
if (print_provides)
rpmdsPrint(NULL, rpmfcProvides(fc), stdout);
if (print_requires)
rpmdsPrint(NULL, rpmfcRequires(fc), stdout);
- fc = rpmfcFree(fc);
-
ec = 0;
exit:
- optCon = rpmcliFini(optCon);
+ argvFree(av);
+ rpmfcFree(fc);
+ rpmcliFini(optCon);
return ec;
}