lib/depends.c: Fix minor memory leak.
authorjbj <devnull@localhost>
Tue, 30 Nov 1999 18:07:08 +0000 (18:07 +0000)
committerjbj <devnull@localhost>
Tue, 30 Nov 1999 18:07:08 +0000 (18:07 +0000)
lib/fprint.c: Pass both dirName/baseName to fpLookup() to avoid memory leaks.
lib/rpmdb.c: ditto, and use scaremem=1.
lib/transaction.c: Fix minor memory leak.

CVS patchset: 3443
CVS date: 1999/11/30 18:07:08

lib/depends.c
lib/fprint.c
lib/fprint.h
lib/rpmdb.c
lib/transaction.c
po/rpm.pot
rpm.spec

index 4670c39..c90f718 100644 (file)
@@ -1358,15 +1358,9 @@ int rpmdepCheck(rpmTransactionSet rpmdep,
 {
     struct availablePackage * p;
     int i, j;
-    const char ** baseNames, ** dirNames;
-    int_32 * dirIndexes;
-    int fileCount;
     int rc;
     Header h = NULL;
     struct problemsSet ps;
-    char * filespec = NULL;
-    int fileAlloced = 0;
-    int len;
 
     ps.alloced = 5;
     ps.num = 0;
@@ -1409,9 +1403,6 @@ int rpmdepCheck(rpmTransactionSet rpmdep,
 
     /* now look at the removed packages and make sure they aren't critical */
     for (i = 0; i < rpmdep->numRemovedPackages; i++) {
-       const char *name;
-       const char ** provides;
-       int providesCount;
 
        h = rpmdbGetRecord(rpmdep->db, rpmdep->removedPackages[i]);
        if (h == NULL) {
@@ -1421,52 +1412,69 @@ int rpmdepCheck(rpmTransactionSet rpmdep,
            goto exit;
        }
 
-       headerNVR(h, &name, NULL, NULL);
+       {   const char * name;
+           headerNVR(h, &name, NULL, NULL);
 
-       /* Erasing: check name against requiredby matches. */
-       if (checkDependentPackages(rpmdep, &ps, name))
-           goto exit;
+           /* Erasing: check name against requiredby matches. */
+           if (checkDependentPackages(rpmdep, &ps, name))
+               goto exit;
+       }
 
-       if (headerGetEntry(h, RPMTAG_PROVIDENAME, NULL, (void **) &provides,
-                &providesCount)) {
-           rc = 0;
-           for (j = 0; j < providesCount; j++) {
-               /* Erasing: check provides against requiredby matches. */
-               if (checkDependentPackages(rpmdep, &ps, provides[j])) {
+       {   const char ** provides;
+           int providesCount;
+
+           if (headerGetEntry(h, RPMTAG_PROVIDENAME, NULL, (void **) &provides,
+                               &providesCount)) {
+               rc = 0;
+               for (j = 0; j < providesCount; j++) {
+                   /* Erasing: check provides against requiredby matches. */
+                   if (checkDependentPackages(rpmdep, &ps, provides[j])) {
                    rc = 1;
                    break;
+                   }
                }
+               xfree(provides);
+               if (rc)
+                   goto exit;
            }
-           free(provides);
-           if (rc)     goto exit;
        }
 
-       if (headerGetEntry(h, RPMTAG_COMPFILELIST, NULL, 
+       {   const char ** baseNames, ** dirNames;
+           int_32 * dirIndexes;
+           int fileCount;
+           char * fileName = NULL;
+           int fileAlloced = 0;
+           int len;
+
+           if (headerGetEntry(h, RPMTAG_COMPFILELIST, NULL, 
                           (void **) &baseNames, &fileCount)) {
-           headerGetEntry(h, RPMTAG_COMPDIRLIST, NULL, 
+               headerGetEntry(h, RPMTAG_COMPDIRLIST, NULL, 
                            (void **) &dirNames, NULL);
-           headerGetEntry(h, RPMTAG_COMPFILEDIRS, NULL, 
+               headerGetEntry(h, RPMTAG_COMPFILEDIRS, NULL, 
                            (void **) &dirIndexes, NULL);
-           rc = 0;
-           for (j = 0; j < fileCount; j++) {
-               len = strlen(baseNames[j]) + 1 + 
-                     strlen(dirNames[dirIndexes[j]]);
-               if (len > fileAlloced) {
-                   fileAlloced = len * 2;
-                   filespec = xrealloc(filespec, fileAlloced);
+               rc = 0;
+               for (j = 0; j < fileCount; j++) {
+                   len = strlen(baseNames[j]) + 1 + 
+                         strlen(dirNames[dirIndexes[j]]);
+                   if (len > fileAlloced) {
+                       fileAlloced = len * 2;
+                       fileName = xrealloc(fileName, fileAlloced);
+                   }
+                   strcpy(fileName, dirNames[dirIndexes[j]]);
+                   strcat(fileName, baseNames[j]);
+                   /* Erasing: check filename against requiredby matches. */
+                   if (checkDependentPackages(rpmdep, &ps, fileName)) {
+                       rc = 1;
+                       break;
+                   }
                }
-               strcpy(filespec, dirNames[dirIndexes[j]]);
-               strcat(filespec, baseNames[j]);
-               /* Erasing: check filename against requiredby matches. */
-               if (checkDependentPackages(rpmdep, &ps, filespec)) {
-                   rc = 1;
-                   break;
-               }
-           }
 
-           free(baseNames);
-           free(dirNames);
-           if (rc) goto exit;
+               free(fileName);
+               free(baseNames);
+               free(dirNames);
+               if (rc)
+                   goto exit;
+           }
        }
 
        headerFree(h);  h = NULL;
@@ -1485,8 +1493,6 @@ int rpmdepCheck(rpmTransactionSet rpmdep,
 exit:
     if (h) 
        headerFree(h);
-    if (filespec)
-       free(filespec);
     if (ps.problems)   free(ps.problems);
     return 1;
 }
index affcca8..7511ccf 100644 (file)
@@ -95,13 +95,15 @@ static fingerPrint doLookup(fingerPrintCache cache, const char * dirName,
                fp.subDir++;
            else
                fp.subDir = "";
-           if (!scareMemory && fp.subDir != NULL)
-               fp.subDir = xstrdup(fp.subDir); /* XXX memory leak, but how
-                                                  do we know we can free it? 
-                                                  Using the (new) cache would
-                                                  work if hash tables allowed
-                                                  traversal. */
            fp.baseName = baseName;
+           if (!scareMemory && fp.subDir != NULL) {
+               /* XXX memory leak, but how do we know we can free it? 
+                * XXX Using the (new) cache would work if hash tables
+                * XXX allowed traversal.
+                */
+               fp.subDir = xstrdup(fp.subDir);
+               fp.baseName = xstrdup(fp.baseName);
+           }
            return fp;
        }
 
@@ -117,18 +119,10 @@ static fingerPrint doLookup(fingerPrintCache cache, const char * dirName,
     return fp;
 }
 
-fingerPrint fpLookup(fingerPrintCache cache, const char * fullName, 
-                    int scareMemory)
+fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, 
+                       const char * baseName, int scareMemory)
 {
-    char *dn = strcpy(alloca(strlen(fullName)+1), fullName);
-    char *bn = strrchr(dn, '/');
-
-    if (bn)
-       *bn++ = '\0';
-    else
-       bn = dn;
-
-    return doLookup(cache, dn, bn, scareMemory);
+    return doLookup(cache, dirName, baseName, scareMemory);
 }
 
 unsigned int fpHashFunction(const void * key)
index 913412a..2dae676 100644 (file)
@@ -39,8 +39,8 @@ extern "C" {
 /* Be carefull with the memory... assert(*fullName == '/' || !scareMemory) */
 fingerPrintCache fpCacheCreate(int sizeHint);
 void fpCacheFree(fingerPrintCache cache);
-fingerPrint fpLookup(fingerPrintCache cache, const char * fullName, 
-                    int scareMemory);
+fingerPrint fpLookup(fingerPrintCache cache, const char * dirName, 
+                       const char * baseName, int scareMemory);
 
 /* Hash based on dev and inode only! */
 unsigned int fpHashFunction(const void * key);
index 0ff2a61..7e59ae7 100644 (file)
@@ -355,21 +355,29 @@ Header rpmdbGetRecord(rpmdb db, unsigned int offset)
 
 int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches)
 {
+    const char * dirName;
     const char * baseName;
     fingerPrint fp1, fp2;
     dbiIndexSet allMatches;
-    int i, rc, num;
+    int i, rc;
     Header h;
     fingerPrintCache fpc;
 
-    fpc = fpCacheCreate(20);
-    fp1 = fpLookup(fpc, filespec, 0);
-
-    baseName = strrchr(filespec, '/');
-    if (baseName == NULL) 
-       baseName = filespec;
-    else
+    {  char * t = strcpy(alloca(strlen(filespec)+1), filespec);
+       char * te = strrchr(t, '/');
+       if (te) {
+           te++;
+           *te = '\0';
+       }
+       dirName = t;
+    }
+    if ((baseName = strrchr(filespec, '/')) != NULL)
        baseName++;
+    else
+       baseName = filespec;
+
+    fpc = fpCacheCreate(20);
+    fp1 = fpLookup(fpc, dirName, baseName, 1);
 
     rc = dbiSearchIndex(db->fileIndex, baseName, &allMatches);
     if (rc) {
@@ -382,7 +390,6 @@ int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches)
     while (i < allMatches.count) {
        const char ** baseNames, ** dirNames;
        int_32 * dirIndexes;
-       char * otherFile;
 
        if ((h = rpmdbGetRecord(db, allMatches.recs[i].recOffset)) == NULL) {
            i++;
@@ -397,17 +404,12 @@ int rpmdbFindByFile(rpmdb db, const char * filespec, dbiIndexSet * matches)
                                (void **) &dirNames, NULL);
 
        do {
-           num = allMatches.recs[i].fileNumber;
-           otherFile = xmalloc(strlen(dirNames[dirIndexes[num]]) + 
-                             strlen(baseNames[num]) + 1);
-           strcpy(otherFile, dirNames[dirIndexes[num]]);
-           strcat(otherFile, baseNames[num]);
+           int num = allMatches.recs[i].fileNumber;
 
-           fp2 = fpLookup(fpc, otherFile, 1);
+           fp2 = fpLookup(fpc, dirNames[dirIndexes[num]], baseNames[num], 1);
            if (FP_EQUAL(fp1, fp2))
                dbiAppendIndexRecord(matches, allMatches.recs[i]);
 
-           free(otherFile);
            i++;
        } while ((i < allMatches.count) && 
                        ((i == 0) || (allMatches.recs[i].recOffset == 
index 4ebe009..a527be1 100644 (file)
@@ -94,7 +94,7 @@ static void freeFi(TFI_t *fi)
        if (fi->bnl) {
            free(fi->bnl); fi->bnl = NULL;
            free(fi->dnl); fi->dnl = NULL;
-           fi->dil = NULL;
+           free(fi->dil); fi->dil = NULL;
        }
        if (fi->flinks) {
            free(fi->flinks); fi->flinks = NULL;
index 34a536a..b9b7162 100644 (file)
@@ -6,7 +6,7 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
-"POT-Creation-Date: 1999-11-30 09:22-0500\n"
+"POT-Creation-Date: 1999-11-30 12:53-0500\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -65,59 +65,59 @@ msgstr ""
 msgid "Building for target %s\n"
 msgstr ""
 
-#: build.c:346
+#: build.c:344
 msgid "buildroot already specified"
 msgstr ""
 
-#: build.c:353
+#: build.c:351
 msgid "--buildarch has been obsoleted.  Use the --target option instead.\n"
 msgstr ""
 
-#: build.c:357
+#: build.c:355
 msgid "--buildos has been obsoleted.  Use the --target option instead.\n"
 msgstr ""
 
-#: build.c:378
+#: build.c:376
 msgid "override build architecture"
 msgstr ""
 
-#: build.c:380
+#: build.c:378
 msgid "override build operating system"
 msgstr ""
 
-#: build.c:382
+#: build.c:380
 msgid "override build root"
 msgstr ""
 
-#: build.c:384 rpm.c:493
+#: build.c:382 rpm.c:493
 msgid "remove build tree when done"
 msgstr ""
 
-#: build.c:386
+#: build.c:384
 msgid "do not execute any stages of the build"
 msgstr ""
 
-#: build.c:388
+#: build.c:386
 msgid "do not accept I18N msgstr's from specfile"
 msgstr ""
 
-#: build.c:390
+#: build.c:388
 msgid "remove sources when done"
 msgstr ""
 
-#: build.c:392
+#: build.c:390
 msgid "remove specfile when done"
 msgstr ""
 
-#: build.c:394 rpm.c:491
+#: build.c:392 rpm.c:491
 msgid "skip straight to specified stage (only for c,i)"
 msgstr ""
 
-#: build.c:396
+#: build.c:394
 msgid "override target platform"
 msgstr ""
 
-#: build.c:398
+#: build.c:396
 msgid "lookup I18N strings in specfile catalog"
 msgstr ""
 
@@ -2070,7 +2070,7 @@ msgstr ""
 msgid "package %s conflicts: %s\n"
 msgstr ""
 
-#: lib/depends.c:1111 lib/depends.c:1419
+#: lib/depends.c:1111 lib/depends.c:1410
 #, c-format
 msgid "cannot read header at %d for dependency check"
 msgstr ""
@@ -2229,73 +2229,73 @@ msgstr ""
 msgid "installing a source package\n"
 msgstr ""
 
-#: lib/install.c:416
+#: lib/install.c:426
 #, c-format
 msgid "cannot create sourcedir %s"
 msgstr ""
 
-#: lib/install.c:422 lib/install.c:442
+#: lib/install.c:432 lib/install.c:462
 #, c-format
 msgid "cannot write to %s"
 msgstr ""
 
-#: lib/install.c:426
+#: lib/install.c:436
 #, c-format
 msgid "sources in: %s\n"
 msgstr ""
 
-#: lib/install.c:436
+#: lib/install.c:456
 #, c-format
 msgid "cannot create specdir %s"
 msgstr ""
 
-#: lib/install.c:446
+#: lib/install.c:466
 #, c-format
 msgid "spec file in: %s\n"
 msgstr ""
 
-#: lib/install.c:480 lib/install.c:508
+#: lib/install.c:500 lib/install.c:528
 msgid "source package contains no .spec file"
 msgstr ""
 
-#: lib/install.c:530
+#: lib/install.c:550
 #, c-format
 msgid "renaming %s to %s\n"
 msgstr ""
 
-#: lib/install.c:532 lib/install.c:811 lib/uninstall.c:27
+#: lib/install.c:552 lib/install.c:831 lib/uninstall.c:27
 #, c-format
 msgid "rename of %s to %s failed: %s"
 msgstr ""
 
-#: lib/install.c:623
+#: lib/install.c:643
 msgid "source package expected, binary found"
 msgstr ""
 
-#: lib/install.c:680
+#: lib/install.c:700
 #, c-format
 msgid "package: %s-%s-%s files test = %d\n"
 msgstr ""
 
-#: lib/install.c:741
+#: lib/install.c:761
 msgid "stopping install as we're running --test\n"
 msgstr ""
 
-#: lib/install.c:746
+#: lib/install.c:766
 msgid "running preinstall script (if any)\n"
 msgstr ""
 
-#: lib/install.c:771
+#: lib/install.c:791
 #, c-format
 msgid "warning: %s created as %s"
 msgstr ""
 
-#: lib/install.c:807
+#: lib/install.c:827
 #, c-format
 msgid "warning: %s saved as %s"
 msgstr ""
 
-#: lib/install.c:881
+#: lib/install.c:901
 msgid "running postinstall scripts (if any)\n"
 msgstr ""
 
@@ -2857,76 +2857,76 @@ msgid ""
 "database"
 msgstr ""
 
-#: lib/rpmdb.c:467
+#: lib/rpmdb.c:469
 #, c-format
 msgid "package %s not listed in %s"
 msgstr ""
 
-#: lib/rpmdb.c:478
+#: lib/rpmdb.c:480
 #, c-format
 msgid "package %s not found in %s"
 msgstr ""
 
-#: lib/rpmdb.c:502 lib/uninstall.c:86
+#: lib/rpmdb.c:504 lib/uninstall.c:86
 #, c-format
 msgid "cannot read header at %d for uninstall"
 msgstr ""
 
-#: lib/rpmdb.c:510
+#: lib/rpmdb.c:512
 msgid "package has no name"
 msgstr ""
 
-#: lib/rpmdb.c:512
+#: lib/rpmdb.c:514
 msgid "removing name index\n"
 msgstr ""
 
-#: lib/rpmdb.c:517
+#: lib/rpmdb.c:519
 msgid "package has no group\n"
 msgstr ""
 
-#: lib/rpmdb.c:519
+#: lib/rpmdb.c:521
 msgid "removing group index\n"
 msgstr ""
 
-#: lib/rpmdb.c:526
+#: lib/rpmdb.c:528
 #, c-format
 msgid "removing provides index for %s\n"
 msgstr ""
 
-#: lib/rpmdb.c:541
+#: lib/rpmdb.c:543
 #, c-format
 msgid "removing requiredby index for %s\n"
 msgstr ""
 
-#: lib/rpmdb.c:553
+#: lib/rpmdb.c:555
 #, c-format
 msgid "removing trigger index for %s\n"
 msgstr ""
 
-#: lib/rpmdb.c:564
+#: lib/rpmdb.c:566
 #, c-format
 msgid "removing conflict index for %s\n"
 msgstr ""
 
-#: lib/rpmdb.c:575
+#: lib/rpmdb.c:577
 #, c-format
 msgid "removing file index for %s\n"
 msgstr ""
 
-#: lib/rpmdb.c:584
+#: lib/rpmdb.c:586
 msgid "package has no files\n"
 msgstr ""
 
-#: lib/rpmdb.c:686
+#: lib/rpmdb.c:688
 msgid "cannot allocate space for database"
 msgstr ""
 
-#: lib/rpmdb.c:745
+#: lib/rpmdb.c:747
 #, c-format
 msgid "cannot read header at %d for update"
 msgstr ""
 
-#: lib/rpmdb.c:757
+#: lib/rpmdb.c:759
 msgid "header changed size!"
 msgstr ""
 
index 90d64f6..d79cac8 100644 (file)
--- a/rpm.spec
+++ b/rpm.spec
@@ -2,7 +2,7 @@ Summary: The Red Hat package management system.
 Name: rpm
 %define version 3.0.4
 Version: %{version}
-Release: 0.1
+Release: 0.2
 Group: System Environment/Base
 Source: ftp://ftp.rpm.org/pub/rpm/dist/rpm-3.0.x/rpm-%{version}.tar.gz
 Copyright: GPL