diff options
author | jbj <devnull@localhost> | 1999-11-30 18:07:08 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 1999-11-30 18:07:08 +0000 |
commit | 06aedc29ca90537e91d0ed2b7a90493a8bd7d8e8 (patch) | |
tree | 04f9a82d3ac694eb20321a3c9d3c51d294ab74a6 /lib | |
parent | 4e56943831a57ab9cc00182007ee55c6fc46ba1e (diff) | |
download | librpm-tizen-06aedc29ca90537e91d0ed2b7a90493a8bd7d8e8.tar.gz librpm-tizen-06aedc29ca90537e91d0ed2b7a90493a8bd7d8e8.tar.bz2 librpm-tizen-06aedc29ca90537e91d0ed2b7a90493a8bd7d8e8.zip |
lib/depends.c: Fix minor memory leak.
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/depends.c | 94 | ||||
-rw-r--r-- | lib/fprint.c | 28 | ||||
-rw-r--r-- | lib/fprint.h | 4 | ||||
-rw-r--r-- | lib/rpmdb.c | 34 | ||||
-rw-r--r-- | lib/transaction.c | 2 |
5 files changed, 82 insertions, 80 deletions
diff --git a/lib/depends.c b/lib/depends.c index 4670c3921..c90f718ce 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -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; } diff --git a/lib/fprint.c b/lib/fprint.c index affcca89a..7511ccfb0 100644 --- a/lib/fprint.c +++ b/lib/fprint.c @@ -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) diff --git a/lib/fprint.h b/lib/fprint.h index 913412a3b..2dae67630 100644 --- a/lib/fprint.h +++ b/lib/fprint.h @@ -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); diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 0ff2a6161..7e59ae7ed 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -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 == diff --git a/lib/transaction.c b/lib/transaction.c index 4ebe009ec..a527be1bb 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -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; |