Spring-cleaning for rpmdeps
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 30 May 2011 07:44:43 +0000 (10:44 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 30 May 2011 07:44:43 +0000 (10:44 +0300)
- 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

tools/rpmdeps.c

index 438209c..6b0b527 100644 (file)
@@ -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;
 }