summaryrefslogtreecommitdiff
path: root/lib/fprint.c
diff options
context:
space:
mode:
authorjbj <devnull@localhost>1999-10-29 16:06:01 +0000
committerjbj <devnull@localhost>1999-10-29 16:06:01 +0000
commit1e0138188b4887431444d90395be0f2fac5c2db3 (patch)
tree921cdb01039a413878fd312ff4656c75dc32a4db /lib/fprint.c
parent0d0b405c201b43f2eebc61257f5992931e1cdb0c (diff)
downloadlibrpm-tizen-1e0138188b4887431444d90395be0f2fac5c2db3.tar.gz
librpm-tizen-1e0138188b4887431444d90395be0f2fac5c2db3.tar.bz2
librpm-tizen-1e0138188b4887431444d90395be0f2fac5c2db3.zip
check for memory leaks (almost all leaks are plugged).
CVS patchset: 3403 CVS date: 1999/10/29 16:06:01
Diffstat (limited to 'lib/fprint.c')
-rw-r--r--lib/fprint.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/fprint.c b/lib/fprint.c
index 94f597416..41d91a72a 100644
--- a/lib/fprint.c
+++ b/lib/fprint.c
@@ -3,16 +3,20 @@
#include <rpmlib.h>
#include "fprint.h"
-fingerPrintCache fpCacheCreate(int sizeHint) {
+fingerPrintCache fpCacheCreate(int sizeHint)
+{
fingerPrintCache fpc;
fpc = xmalloc(sizeof(*fpc));
- fpc->ht = htCreate(sizeHint * 2, sizeof(char *), hashFunctionString,
+ fpc->ht = htCreate(sizeHint * 2, sizeof(char *), 1, hashFunctionString,
hashEqualityString);
return fpc;
}
-void fpCacheFree(fingerPrintCache cache) {
+void fpCacheFree(fingerPrintCache cache)
+{
+ htFree(cache->ht);
+ free(cache);
}
static const struct fprintCacheEntry_s * cacheContainsDirectory(
@@ -35,7 +39,6 @@ static fingerPrint doLookup(fingerPrintCache cache, const char * dirName,
struct stat sb;
char * buf;
const struct fprintCacheEntry_s * cacheHit;
- struct fprintCacheEntry_s * newEntry;
/* assert(*dirName == '/' || !scareMemory); */
@@ -72,15 +75,18 @@ static fingerPrint doLookup(fingerPrintCache cache, const char * dirName,
if ((cacheHit = cacheContainsDirectory(cache, *buf ? buf : "/"))) {
fp.entry = cacheHit;
} else if (!stat(*buf ? buf : "/", &sb)) {
- newEntry = xmalloc(sizeof(*fp.entry));
+ size_t nb = sizeof(*fp.entry) + (*buf ? strlen(buf) : 1) + 1;
+ char * dn = xmalloc(nb);
+ struct fprintCacheEntry_s * newEntry = (void *)dn;
+ dn += sizeof(*newEntry);
+ strcpy(dn, (*buf ? buf : "/"));
newEntry->ino = sb.st_ino;
newEntry->dev = sb.st_dev;
newEntry->isFake = 0;
- newEntry->dirName = xstrdup(*buf ? buf : "/");
+ newEntry->dirName = dn;
fp.entry = newEntry;
- /* XXX FIXME: memory leak */
- htAddEntry(cache->ht, xstrdup(*buf ? buf : "/"), fp.entry);
+ htAddEntry(cache->ht, dn, fp.entry);
}
if (fp.entry) {
@@ -112,7 +118,8 @@ static fingerPrint doLookup(fingerPrintCache cache, const char * dirName,
}
fingerPrint fpLookup(fingerPrintCache cache, const char * fullName,
- int scareMemory) {
+ int scareMemory)
+{
char *dn = strcpy(alloca(strlen(fullName)+1), fullName);
char *bn = strrchr(dn, '/');
@@ -152,7 +159,8 @@ int fpEqual(const void * key1, const void * key2)
void fpLookupList(fingerPrintCache cache, const char ** dirNames,
const char ** baseNames, const int * dirIndexes,
- int fileCount, fingerPrint * fpList) {
+ int fileCount, fingerPrint * fpList)
+{
int i;
for (i = 0; i < fileCount; i++) {
@@ -169,7 +177,8 @@ void fpLookupList(fingerPrintCache cache, const char ** dirNames,
}
}
-void fpLookupHeader(fingerPrintCache cache, Header h, fingerPrint * fpList) {
+void fpLookupHeader(fingerPrintCache cache, Header h, fingerPrint * fpList)
+{
int fileCount;
const char ** baseNames, ** dirNames;
int_32 * dirIndexes;