summaryrefslogtreecommitdiff
path: root/build
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 /build
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 'build')
-rw-r--r--build/files.c43
-rw-r--r--build/names.c13
-rw-r--r--build/pack.c3
-rw-r--r--build/parsePreamble.c17
-rw-r--r--build/rpmbuild.h1
5 files changed, 48 insertions, 29 deletions
diff --git a/build/files.c b/build/files.c
index 197f2ad30..83e02af49 100644
--- a/build/files.c
+++ b/build/files.c
@@ -213,19 +213,20 @@ static char *strtokWithQuotes(char *s, char *delim)
static void timeCheck(int tc, Header h)
{
int *mtime;
- char **file;
+ char **files;
int count, x, currentTime;
- headerGetEntry(h, RPMTAG_OLDFILENAMES, NULL, (void **) &file, &count);
+ headerGetEntry(h, RPMTAG_OLDFILENAMES, NULL, (void **) &files, &count);
headerGetEntry(h, RPMTAG_FILEMTIMES, NULL, (void **) &mtime, NULL);
currentTime = time(NULL);
for (x = 0; x < count; x++) {
if (currentTime - mtime[x] > tc) {
- rpmMessage(RPMMESS_WARNING, _("TIMECHECK failure: %s\n"), file[x]);
+ rpmMessage(RPMMESS_WARNING, _("TIMECHECK failure: %s\n"), files[x]);
}
}
+ FREE(files);
}
typedef struct VFA {
@@ -591,11 +592,14 @@ static int parseForRegexLang(const char *fileName, /*@out@*/char **lang)
if (! initialized) {
const char *patt = rpmExpand("%{_langpatt}", NULL);
+ int rc = 0;
if (!(patt && *patt != '%'))
- return 1;
- if (regcomp(&compiledPatt, patt, REG_EXTENDED))
- return -1;
+ rc = 1;
+ else if (regcomp(&compiledPatt, patt, REG_EXTENDED))
+ rc = -1;
xfree(patt);
+ if (rc)
+ return rc;
hasRegex = 1;
initialized = 1;
}
@@ -1170,11 +1174,12 @@ static int processPackageFiles(Spec spec, Package pkg,
ffn = rpmGetPath("%{_builddir}/",
(spec->buildSubdir ? spec->buildSubdir : "") ,
"/", pkg->fileFile, NULL);
+ f = fopen(ffn, "r");
+ xfree(ffn);
- if ((f = fopen(ffn, "r")) == NULL) {
+ if (f == NULL) {
rpmError(RPMERR_BADFILENAME,
_("Could not open %%files file: %s"), pkg->fileFile);
- FREE(ffn);
return RPMERR_BADFILENAME;
}
while (fgets(buf, sizeof(buf), f)) {
@@ -1186,12 +1191,11 @@ static int processPackageFiles(Spec spec, Package pkg,
appendStringBuf(pkg->fileList, buf);
}
fclose(f);
- FREE(ffn);
}
/* Init the file list structure */
- /* XXX spec->buildRoot == NULL, then strdup("") is returned */
+ /* XXX spec->buildRoot == NULL, then xstrdup("") is returned */
fl.buildRoot = rpmGetPath(spec->buildRoot, NULL);
if (headerGetEntry(pkg->header, RPMTAG_DEFAULTPREFIX,
@@ -1354,8 +1358,11 @@ void initSourceHeader(Spec spec)
spec->sourceHeader = headerNew();
/* Only specific tags are added to the source package header */
- hi = headerInitIterator(spec->packages->header);
- while (headerNextIterator(hi, &tag, &type, &ptr, &count)) {
+ for (hi = headerInitIterator(spec->packages->header);
+ headerNextIterator(hi, &tag, &type, &ptr, &count);
+ ptr = ((type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE)
+ ? xfree(ptr), NULL : NULL))
+ {
switch (tag) {
case RPMTAG_NAME:
case RPMTAG_VERSION:
@@ -1381,18 +1388,16 @@ void initSourceHeader(Spec spec)
/* do not copy */
break;
}
- if (type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE) {
- FREE(ptr);
- }
}
headerFreeIterator(hi);
/* Add the build restrictions */
- hi = headerInitIterator(spec->buildRestrictions);
- while (headerNextIterator(hi, &tag, &type, &ptr, &count)) {
+ for (hi = headerInitIterator(spec->buildRestrictions);
+ headerNextIterator(hi, &tag, &type, &ptr, &count);
+ ptr = ((type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE)
+ ? xfree(ptr), NULL : NULL))
+ {
headerAddEntry(spec->sourceHeader, tag, type, ptr, count);
- if (type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE)
- FREE(ptr);
}
headerFreeIterator(hi);
diff --git a/build/names.c b/build/names.c
index 806bb617c..60ef5b684 100644
--- a/build/names.c
+++ b/build/names.c
@@ -5,13 +5,22 @@
#include "rpmbuild.h"
static uid_t uids[1024];
-/*@owned@*/ /*@null@*/ static char *unames[1024];
+/*@owned@*/ /*@null@*/ static const char *unames[1024];
static int uid_used = 0;
static gid_t gids[1024];
-/*@owned@*/ /*@null@*/ static char *gnames[1024];
+/*@owned@*/ /*@null@*/ static const char *gnames[1024];
static int gid_used = 0;
+void freeNames(void)
+{
+ int x;
+ for (x = 0; x < uid_used; x++)
+ xfree(unames[x]);
+ for (x = 0; x < gid_used; x++)
+ xfree(gnames[x]);
+}
+
/*
* getUname() takes a uid, gets the username, and creates an entry in the
* table to hold a string containing the user name.
diff --git a/build/pack.c b/build/pack.c
index d8db32069..143cd7712 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -69,6 +69,7 @@ int packageSources(Spec spec)
rc = writeRPM(spec->sourceHeader, fn, RPMLEAD_SOURCE,
csa, spec->passPhrase, &(spec->cookie));
+ free(csa->cpioFdIn);
xfree(fn);
}
return rc;
@@ -126,6 +127,7 @@ int packageBinaries(Spec spec)
char *binRpm, *binDir;
binRpm = headerSprintf(pkg->header, binFormat, rpmTagTable,
rpmHeaderFormats, &errorString);
+ xfree(binFormat);
if (binRpm == NULL) {
headerGetEntry(pkg->header, RPMTAG_NAME, NULL,
(void **)&name, NULL);
@@ -164,6 +166,7 @@ int packageBinaries(Spec spec)
rc = writeRPM(pkg->header, fn, RPMLEAD_BINARY,
csa, spec->passPhrase, NULL);
+ free(csa->cpioFdIn);
xfree(fn);
if (rc)
return rc;
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
index 8cffc5a09..ee1eeeee0 100644
--- a/build/parsePreamble.c
+++ b/build/parsePreamble.c
@@ -185,15 +185,16 @@ static int checkForDuplicates(Header h, char *name)
#if 0 /* XXX harmless, but headerInitIterator() does this anyways */
headerSort(h);
#endif
- hi = headerInitIterator(h);
- lastTag = 0;
- while (headerNextIterator(hi, &tag, NULL, NULL, NULL)) {
- if (tag == lastTag) {
- rpmError(RPMERR_BADSPEC, _("Duplicate %s entries in package: %s"),
+
+ for (hi = headerInitIterator(h), lastTag = 0;
+ headerNextIterator(hi, &tag, NULL, NULL, NULL);
+ lastTag = tag)
+ {
+ if (tag != lastTag)
+ continue;
+ rpmError(RPMERR_BADSPEC, _("Duplicate %s entries in package: %s"),
tagName(tag), name);
- res = 1;
- }
- lastTag = tag;
+ res = 1;
}
headerFreeIterator(hi);
diff --git a/build/rpmbuild.h b/build/rpmbuild.h
index 9284fa931..a874e6438 100644
--- a/build/rpmbuild.h
+++ b/build/rpmbuild.h
@@ -69,6 +69,7 @@ extern "C" {
/* from build/names.h */
+void freeNames(void);
/*@observer@*/ const char *getUname(uid_t uid);
/*@observer@*/ const char *getUnameS(const char *uname);
/*@observer@*/ const char *getGname(gid_t gid);