diff options
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | build/pack.c | 12 | ||||
-rw-r--r-- | build/spec.c | 11 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rwxr-xr-x | db3/configure | 7 | ||||
-rw-r--r-- | lib/depends.c | 4 | ||||
-rw-r--r-- | lib/fsm.c | 18 | ||||
-rw-r--r-- | lib/header.c | 176 | ||||
-rw-r--r-- | lib/header.h | 3 | ||||
-rw-r--r-- | lib/package.c | 6 | ||||
-rw-r--r-- | lib/psm.c | 80 | ||||
-rw-r--r-- | lib/psm.h | 1 | ||||
-rw-r--r-- | lib/query.c | 2 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 8 | ||||
-rw-r--r-- | lib/rpminstall.c | 4 | ||||
-rw-r--r-- | lib/rpmlib.h | 10 | ||||
-rw-r--r-- | lib/signature.c | 6 | ||||
-rw-r--r-- | lib/stringbuf.c | 6 | ||||
-rw-r--r-- | lib/transaction.c | 31 | ||||
-rw-r--r-- | rpmdb/rpmdb.c | 15 |
20 files changed, 225 insertions, 177 deletions
@@ -61,6 +61,7 @@ - add armv3l arch. - fix: i18n strings need 1 on sucess return code (#41313). - fix: skip %ghost files when building packages (#38218). + - headerFree() returns NULL, _free is C++ safe. 4.0 -> 4.0.[12] - add doxygen and lclint annotations most everywhere. diff --git a/build/pack.c b/build/pack.c index 0ca53f89d..f36f1cde7 100644 --- a/build/pack.c +++ b/build/pack.c @@ -284,10 +284,7 @@ int readRPM(const char *fileName, Spec *specp, struct rpmlead *lead, Header *sig spec->packages = newPackage(spec); /* XXX the header just allocated will be allocated again */ - if (spec->packages->header != NULL) { - headerFree(spec->packages->header); - spec->packages->header = NULL; - } + spec->packages->header = headerFree(spec->packages->header); /* Read the rpm lead and header */ rc = rpmReadPackageInfo(fdi, sigs, &spec->packages->header); @@ -550,7 +547,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, #endif rc = headerWrite(fd, nh, HEADER_MAGIC_YES); - headerFree(nh); + nh = headerFree(nh); if (rc) { rpmError(RPMERR_NOSPACE, _("Unable to write header to %s: %s\n"), @@ -578,10 +575,7 @@ int writeRPM(Header *hdrp, const char *fileName, int type, rc = 0; exit: - if (sig) { - rpmFreeSignature(sig); - sig = NULL; - } + sig = rpmFreeSignature(sig); if (ifd) { (void) Fclose(ifd); ifd = NULL; diff --git a/build/spec.c b/build/spec.c index 4159e7505..e5daf2226 100644 --- a/build/spec.c +++ b/build/spec.c @@ -153,8 +153,7 @@ Package freePackage(Package p) p->postUnFile = _free(p->postUnFile); p->verifyFile = _free(p->verifyFile); - headerFree(p->header); - p->header = NULL; + p->header = headerFree(p->header); p->fileList = freeStringBuf(p->fileList); p->fileFile = _free(p->fileFile); if (p->cpioList) { @@ -490,10 +489,7 @@ Spec freeSpec(Spec spec) rl = _free(rl); } - if (spec->sourceHeader != NULL) { - headerFree(spec->sourceHeader); - spec->sourceHeader = NULL; - } + spec->sourceHeader = headerFree(spec->sourceHeader); if (spec->sourceCpioList) { TFI_t fi = spec->sourceCpioList; @@ -502,8 +498,7 @@ Spec freeSpec(Spec spec) fi = _free(fi); } - headerFree(spec->buildRestrictions); - spec->buildRestrictions = NULL; + spec->buildRestrictions = headerFree(spec->buildRestrictions); if (!spec->recursing) { if (spec->BASpecs != NULL) diff --git a/configure.in b/configure.in index d17aabfe3..99493c232 100644 --- a/configure.in +++ b/configure.in @@ -1046,6 +1046,7 @@ powerpc*) RPMCANONARCH=ppc ;; armv4l*) RPMCANONARCH=armv4l ;; armv4b*) RPMCANONARCH=armv4b ;; arm*) RPMCANONARCH=arm ;; +m68k*) RPMCANONARCH=m68k ;; *) RPMCANONARCH=unknown ;; esac case "${build_os_noversion}" in diff --git a/db3/configure b/db3/configure index 608f1ffa3..ff79eeed6 100755 --- a/db3/configure +++ b/db3/configure @@ -24,5 +24,12 @@ distdir install:\ \ db3_install: all install_setip \\' > Makefile +mv db.h db.h.orig +cat db.h.orig | sed \ + -e '/^struct __db;/i \ +/*@-incondefs@*/' \ + -e '/^struct __key_range;/a \ +/*@=incondefs@*/' > db.h + # Generate manifest for rpmdb. make -s listobjs > db3lobjs diff --git a/lib/depends.c b/lib/depends.c index 6f2206984..90809c6a3 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -172,7 +172,7 @@ static void alFree(struct availableList * al) p->requires = hfd(p->requires, -1); p->requiresEVR = hfd(p->requiresEVR, -1); p->baseNames = hfd(p->baseNames, -1); - if (p->h) headerFree(p->h); + p->h = headerFree(p->h); if (p->relocs) { for (r = p->relocs; (r->oldPath || r->newPath); r++) { @@ -909,7 +909,7 @@ void rpmdepFreeConflicts(struct rpmDependencyConflict * conflicts, int i; for (i = 0; i < numConflicts; i++) { - headerFree(conflicts[i].byHeader); + conflicts[i].byHeader = headerFree(conflicts[i].byHeader); conflicts[i].byName = _free(conflicts[i].byName); conflicts[i].byVersion = _free(conflicts[i].byVersion); conflicts[i].byRelease = _free(conflicts[i].byRelease); @@ -160,11 +160,11 @@ static int mapFind(void * this, const char * fsmPath) int ix = -1; if (fi && fi->fc > 0 && fi->apath && fsmPath && *fsmPath) { - const char ** p; + const char ** p = NULL; - /*@-nullpass@*/ /* LCL: fi->apath != NULL */ - p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath), cpioStrCmp); - /*@=nullpass@*/ + if (fi->apath != NULL) + p = bsearch(&fsmPath, fi->apath, fi->fc, sizeof(fsmPath), + cpioStrCmp); if (p == NULL) { fprintf(stderr, "*** not mapped %s\n", fsmPath); } else { @@ -1098,10 +1098,10 @@ static int fsmMkdirs(/*@special@*/ FSM_t fsm) fsm->ldnalloc = dnlen + 100; fsm->ldn = xrealloc(fsm->ldn, fsm->ldnalloc); } - /*@-nullpass@*/ /* FIX: fsm->ldn NULL. */ - strcpy(fsm->ldn, fsm->path); - /*@=nullpass@*/ - fsm->ldnlen = dnlen; + if (fsm->ldn != NULL) { /* XXX can't happen */ + strcpy(fsm->ldn, fsm->path); + fsm->ldnlen = dnlen; + } } dnli = dnlFreeIterator(dnli); /*@=observertrans =dependenttrans@*/ @@ -1792,13 +1792,13 @@ int fsmStage(FSM_t fsm, fileStage stage) case FSM_MKNOD: /*@-unrecog@*/ rc = mknod(fsm->path, (st->st_mode & ~07777), st->st_rdev); + /*@=unrecog@*/ if (_fsm_debug && (stage & FSM_SYSCALL)) rpmMessage(RPMMESS_DEBUG, " %8s (%s, 0%o, 0x%x) %s\n", cur, fsm->path, (unsigned)(st->st_mode & ~07777), (unsigned)st->st_rdev, (rc < 0 ? strerror(errno) : "")); if (rc < 0) rc = CPIOERR_MKNOD_FAILED; - /*@=unrecog@*/ break; case FSM_LSTAT: rc = Lstat(fsm->path, ost); diff --git a/lib/header.c b/lib/header.c index 348c9c190..08c9681e2 100644 --- a/lib/header.c +++ b/lib/header.c @@ -150,6 +150,16 @@ struct sprintfToken { }; /** + * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. + * @param this memory to free + * @return NULL always + */ +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * p) { + if (p != NULL) free((void *)p); + return NULL; +} + +/** * Return length of entry data. * @param type entry data type * @param p entry data @@ -422,8 +432,8 @@ HeaderIterator headerInitIterator(Header h) void headerFreeIterator(HeaderIterator iter) { - headerFree(iter->h); - free(iter); + iter->h = headerFree(iter->h); + iter = _free(iter); } int headerNextIterator(HeaderIterator hi, @@ -453,6 +463,8 @@ int headerNextIterator(HeaderIterator hi, return ((rc == 1) ? 1 : 0); } +/** + */ static int indexCmp(const void *avp, const void *bvp) /*@*/ { const struct indexEntry * ap = avp, * bp = bvp; @@ -467,6 +479,8 @@ void headerSort(Header h) } } +/** + */ static int offsetCmp(const void *avp, const void *bvp) /*@*/ { const struct indexEntry * ap = avp, * bp = bvp; @@ -635,11 +649,10 @@ assert(rdlen == dl); errxit: /*@-usereleased@*/ if (h) { - if (h->index) free(h->index); + h->index = _free(h->index); /*@-refcounttrans@*/ - free(h); + h = _free(h); /*@=refcounttrans@*/ - h = NULL; } /*@=usereleased@*/ /*@-refcounttrans@*/ @@ -659,7 +672,7 @@ Header headerCopyLoad(void *uh) h = headerLoad(nuh); if (h == NULL) { - free(nuh); + nuh = _free(nuh); return h; } h->region_allocated = 1; @@ -693,6 +706,8 @@ int headerDrips(const Header h) } #endif +/** + */ static /*@only@*/ /*@null@*/ void * doHeaderUnload(Header h, /*@out@*/ int * lengthPtr) /*@modifies h, *lengthPtr @*/ @@ -928,9 +943,7 @@ t = te; errxit: /*@-usereleased@*/ - if (ei) - free(ei); - ei = NULL; + ei = _free(ei); /*@=usereleased@*/ return (void *) ei; } @@ -951,15 +964,15 @@ Header headerReload(Header h, int tag) if (uh == NULL) return NULL; - headerFree(h); + h = headerFree(h); /*@=onlytrans@*/ nh = headerLoad(uh); if (nh == NULL) { - free(uh); + uh = _free(uh); return NULL; } if (nh->region_allocated) - free(uh); + uh = _free(uh); nh->region_allocated = 1; if (ENTRY_IS_REGION(nh->index)) { if (tag == HEADER_SIGNATURES || tag == HEADER_IMMUTABLE) @@ -992,7 +1005,7 @@ int headerWrite(FD_t fd, Header h, enum hMagic magicp) nb = Fwrite(uh, sizeof(char), length, fd); exit: - free((void *)uh); + uh = _free(uh); return (nb == length ? 0 : 1); } @@ -1049,10 +1062,10 @@ Header headerRead(FD_t fd, enum hMagic magicp) exit: if (h) { if (h->region_allocated) - free(ei); + ei = _free(ei); h->region_allocated = 1; } else if (ei) - free(ei); + ei = _free(ei); return h; } @@ -1452,10 +1465,10 @@ Header headerNew() return h; } -void headerFree(Header h) +Header headerFree(Header h) { if (h == NULL || --h->nrefs > 0) - return; + return NULL; /* XXX return previous header? */ if (h->index) { struct indexEntry * entry = h->index; @@ -1465,18 +1478,18 @@ void headerFree(Header h) if (entry->length > 0) { int_32 * ei = entry->data; ei -= 2; /* XXX HACK: adjust to beginning of header. */ - free(ei); + ei = _free(ei); } } else if (!ENTRY_IN_REGION(entry)) { - free(entry->data); + entry->data = _free(entry->data); } entry->data = NULL; } - free(h->index); - h->index = NULL; + h->index = _free(h->index); } - /*@-refcounttrans@*/ free(h); /*@=refcounttrans@*/ + /*@-refcounttrans@*/ h = _free(h); /*@=refcounttrans@*/ + return h; } Header headerLink(Header h) @@ -1545,6 +1558,8 @@ unsigned int headerSizeof(Header h, enum hMagic magicp) return size; } +/** + */ static void copyData(int_32 type, /*@out@*/ void * dstPtr, const void * srcPtr, int_32 c, int dataLength) /*@modifies *dstPtr @*/ @@ -1775,7 +1790,7 @@ int headerAddI18NString(Header h, int_32 tag, const char * string, const char * if (ENTRY_IN_REGION(entry)) { entry->info.offset = 0; } else - free(entry->data); + entry->data = _free(entry->data); /*@-dependenttrans@*/ entry->data = buf; /*@=dependenttrans@*/ @@ -1810,7 +1825,7 @@ int headerModifyEntry(Header h, int_32 tag, int_32 type, void *p, int_32 c) if (ENTRY_IN_REGION(entry)) { entry->info.offset = 0; } else - free(oldData); + oldData = _free(oldData); return 1; } @@ -1880,7 +1895,7 @@ int headerRemoveEntry(Header h, int_32 tag) first->length = 0; if (ENTRY_IN_REGION(first)) continue; - free(data); + data = _free(data); } ne = (first - entry); @@ -1894,6 +1909,8 @@ int headerRemoveEntry(Header h, int_32 tag) return 0; } +/** + */ static char escapedChar(const char ch) /*@*/ { switch (ch) { @@ -1908,21 +1925,27 @@ static char escapedChar(const char ch) /*@*/ } } -static -void freeFormat( /*@only@*/ /*@null@*/ struct sprintfToken * format, int num) +/** + */ +static /*@null@*/ struct sprintfToken * +freeFormat( /*@only@*/ /*@null@*/ struct sprintfToken * format, int num) { int i; - if (format == NULL) return; + if (format == NULL) return NULL; for (i = 0; i < num; i++) { switch (format[i].type) { case PTOK_ARRAY: - freeFormat(format[i].u.array.format, format[i].u.array.numTokens); + format[i].u.array.format = + freeFormat(format[i].u.array.format, + format[i].u.array.numTokens); break; case PTOK_COND: - freeFormat(format[i].u.cond.ifFormat, + format[i].u.cond.ifFormat = + freeFormat(format[i].u.cond.ifFormat, format[i].u.cond.numIfTokens); - freeFormat(format[i].u.cond.elseFormat, + format[i].u.cond.elseFormat = + freeFormat(format[i].u.cond.elseFormat, format[i].u.cond.numElseTokens); break; case PTOK_NONE: @@ -1932,9 +1955,12 @@ void freeFormat( /*@only@*/ /*@null@*/ struct sprintfToken * format, int num) break; } } - free(format); + format = _free(format); + return NULL; } +/** + */ static void findTag(char * name, const struct headerTagTableEntry * tags, const struct headerSprintfExtension * extensions, /*@out@*/const struct headerTagTableEntry ** tagMatch, @@ -1990,6 +2016,8 @@ static int parseExpression(struct sprintfToken * token, char * str, /*@out@*/char ** endPtr, /*@null@*/ /*@out@*/ errmsg_t * errmsg) /*@modifies str, *str, *token, *endPtr, *errmsg @*/; +/** + */ static int parseFormat(char * str, const struct headerTagTableEntry * tags, const struct headerSprintfExtension * extensions, /*@out@*/struct sprintfToken ** formatPtr, /*@out@*/int * numTokensPtr, @@ -2048,7 +2076,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, start++; if (parseExpression(format + currToken, start, tags, extensions, &newEnd, errmsg)) { - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } start = newEnd; @@ -2066,7 +2094,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-observertrans@*/ if (errmsg) *errmsg = _("missing { after %"); /*@=observertrans@*/ - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } @@ -2096,7 +2124,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-observertrans@*/ if (errmsg) *errmsg = _("missing } after %{"); /*@=observertrans@*/ - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } *next++ = '\0'; @@ -2110,7 +2138,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-observertrans@*/ if (errmsg) *errmsg = _("empty tag format"); /*@=observertrans@*/ - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } format[currToken].u.tag.type = chptr; @@ -2122,7 +2150,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-observertrans@*/ if (errmsg) *errmsg = _("empty tag name"); /*@=observertrans@*/ - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } @@ -2139,7 +2167,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-observertrans@*/ if (errmsg) *errmsg = _("unknown tag"); /*@=observertrans@*/ - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } @@ -2158,7 +2186,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, &format[currToken].u.array.format, &format[currToken].u.array.numTokens, &start, PARSER_IN_ARRAY, errmsg)) { - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } @@ -2166,7 +2194,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, /*@-observertrans@*/ if (errmsg) *errmsg = _("] expected at end of array"); /*@=observertrans@*/ - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } @@ -2189,7 +2217,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, if (errmsg) *errmsg = _("unexpected }"); /*@=observertrans@*/ } - freeFormat(format, numTokens); + format = freeFormat(format, numTokens); return 1; } *start++ = '\0'; @@ -2233,6 +2261,8 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, return 0; } +/** + */ static int parseExpression(struct sprintfToken * token, char * str, const struct headerTagTableEntry * tags, const struct headerSprintfExtension * extensions, @@ -2273,8 +2303,8 @@ static int parseExpression(struct sprintfToken * token, char * str, /*@-observertrans@*/ if (errmsg) *errmsg = _("} expected in expression"); /*@=observertrans@*/ - freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); - token->u.cond.ifFormat = NULL; + token->u.cond.ifFormat = + freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); return 1; } @@ -2283,8 +2313,8 @@ static int parseExpression(struct sprintfToken * token, char * str, /*@-observertrans@*/ if (errmsg) *errmsg = _(": expected following ? subexpression"); /*@=observertrans@*/ - freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); - token->u.cond.ifFormat = NULL; + token->u.cond.ifFormat = + freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); return 1; } @@ -2300,8 +2330,8 @@ static int parseExpression(struct sprintfToken * token, char * str, /*@-observertrans@*/ if (errmsg) *errmsg = _("{ expected after : in expression"); /*@=observertrans@*/ - freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); - token->u.cond.ifFormat = NULL; + token->u.cond.ifFormat = + freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); return 1; } @@ -2315,8 +2345,8 @@ static int parseExpression(struct sprintfToken * token, char * str, /*@-observertrans@*/ if (errmsg) *errmsg = _("} expected in expression"); /*@=observertrans@*/ - freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); - token->u.cond.ifFormat = NULL; + token->u.cond.ifFormat = + freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); return 1; } @@ -2325,10 +2355,10 @@ static int parseExpression(struct sprintfToken * token, char * str, /*@-observertrans@*/ if (errmsg) *errmsg = _("| expected at end of expression"); /*@=observertrans@*/ - freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); - token->u.cond.ifFormat = NULL; - freeFormat(token->u.cond.elseFormat, token->u.cond.numElseTokens); - token->u.cond.elseFormat = NULL; + token->u.cond.ifFormat = + freeFormat(token->u.cond.ifFormat, token->u.cond.numIfTokens); + token->u.cond.elseFormat = + freeFormat(token->u.cond.elseFormat, token->u.cond.numElseTokens); return 1; } } @@ -2355,6 +2385,8 @@ static int parseExpression(struct sprintfToken * token, char * str, return 0; } +/** + */ static int getExtension(Header h, headerTagTagFunction fn, /*@out@*/ int_32 * typeptr, /*@out@*/ const void ** data, /*@out@*/ int_32 * countptr, struct extensionCache * ext) @@ -2373,6 +2405,8 @@ static int getExtension(Header h, headerTagTagFunction fn, return 0; } +/** + */ static char * formatValue(struct sprintfTag * tag, Header h, const struct headerSprintfExtension * extensions, struct extensionCache * extCache, int element) @@ -2452,7 +2486,7 @@ static char * formatValue(struct sprintfTag * tag, Header h, } /*@-observertrans -modobserver@*/ - if (mayfree) free((void *)data); + if (mayfree) data = _free(data); /*@=observertrans =modobserver@*/ break; @@ -2501,6 +2535,8 @@ static char * formatValue(struct sprintfTag * tag, Header h, return val; } +/** + */ static const char * singleSprintf(Header h, struct sprintfToken * token, const struct headerSprintfExtension * extensions, struct extensionCache * extCache, int element) @@ -2557,7 +2593,7 @@ static const char * singleSprintf(Header h, struct sprintfToken * token, } strcat(val, thisItem); len += thisItemLen; - free((void *)thisItem); + thisItem = _free(thisItem); } break; @@ -2604,7 +2640,7 @@ static const char * singleSprintf(Header h, struct sprintfToken * token, } strcat(val, thisItem); len += thisItemLen; - free((void *)thisItem); + thisItem = _free(thisItem); } } } @@ -2615,6 +2651,8 @@ static const char * singleSprintf(Header h, struct sprintfToken * token, return val; } +/** + */ static struct extensionCache * allocateExtensionCache( const struct headerSprintfExtension * extensions) /*@*/ @@ -2633,6 +2671,8 @@ static struct extensionCache * allocateExtensionCache( return xcalloc(i, sizeof(struct extensionCache)); } +/** + */ static void freeExtensionCache(const struct headerSprintfExtension * extensions, /*@only@*/struct extensionCache * cache) { @@ -2640,7 +2680,7 @@ static void freeExtensionCache(const struct headerSprintfExtension * extensions, int i = 0; while (ext->type != HEADER_EXT_LAST) { - if (cache[i].freeit) free((void *)cache[i].data); + if (cache[i].freeit) cache[i].data = _free(cache[i].data); i++; if (ext->type == HEADER_EXT_MORE) @@ -2649,7 +2689,7 @@ static void freeExtensionCache(const struct headerSprintfExtension * extensions, ext++; } - free(cache); + cache = _free(cache); } char * headerSprintf(Header h, const char * origFmt, @@ -2671,7 +2711,7 @@ char * headerSprintf(Header h, const char * origFmt, if (parseFormat(fmtString, tags, extensions, &format, &numTokens, NULL, PARSER_BEGIN, errmsg)) { - free(fmtString); + fmtString = _free(fmtString); return NULL; } @@ -2699,17 +2739,19 @@ char * headerSprintf(Header h, const char * origFmt, strcat(answer, piece); answerLength += pieceLength; - free((void *)piece); + piece = _free(piece); } } - free(fmtString); + fmtString = _free(fmtString); freeExtensionCache(extensions, extCache); - free(format); + format = _free(format); return answer; } +/** + */ static char * octalFormat(int_32 type, const void * data, char * formatPrefix, int padding, /*@unused@*/int element) /*@modifies formatPrefix @*/ @@ -2727,6 +2769,8 @@ static char * octalFormat(int_32 type, const void * data, return val; } +/** + */ static char * hexFormat(int_32 type, const void * data, char * formatPrefix, int padding, /*@unused@*/int element) /*@modifies formatPrefix @*/ @@ -2744,6 +2788,8 @@ static char * hexFormat(int_32 type, const void * data, return val; } +/** + */ static char * realDateFormat(int_32 type, const void * data, char * formatPrefix, int padding, /*@unused@*/int element, const char * strftimeFormat) @@ -2773,6 +2819,8 @@ static char * realDateFormat(int_32 type, const void * data, return val; } +/** + */ static char * dateFormat(int_32 type, const void * data, char * formatPrefix, int padding, int element) /*@modifies formatPrefix @*/ @@ -2780,6 +2828,8 @@ static char * dateFormat(int_32 type, const void * data, return realDateFormat(type, data, formatPrefix, padding, element, "%c"); } +/** + */ static char * dayFormat(int_32 type, const void * data, char * formatPrefix, int padding, int element) /*@modifies formatPrefix @*/ @@ -2788,6 +2838,8 @@ static char * dayFormat(int_32 type, const void * data, "%a %b %d %Y"); } +/** + */ static char * shescapeFormat(int_32 type, const void * data, char * formatPrefix, int padding, /*@unused@*/int element) /*@modifies formatPrefix @*/ diff --git a/lib/header.h b/lib/header.h index 50501b180..e3145dc75 100644 --- a/lib/header.h +++ b/lib/header.h @@ -254,8 +254,9 @@ Header headerLink(Header h) /** \ingroup header * Dereference a header instance. * @param h header + * @return NULL always */ -void headerFree( /*@null@*/ /*@killref@*/ Header h); +/*@null@*/ Header headerFree( /*@null@*/ /*@killref@*/ Header h); /** \ingroup header * Return header reference count. diff --git a/lib/package.c b/lib/package.c index 2638ead73..d9e1d2217 100644 --- a/lib/package.c +++ b/lib/package.c @@ -134,7 +134,7 @@ static rpmRC readPackageHeaders(FD_t fd, /*@out@*/ struct rpmlead * leadPtr, ? HEADER_MAGIC_YES : HEADER_MAGIC_NO); if (*hdr == NULL) { if (sigs != NULL) - headerFree(*sigs); + *sigs = rpmFreeSignature(*sigs); return RPMRC_FAIL; } @@ -190,7 +190,7 @@ static rpmRC readPackageHeaders(FD_t fd, /*@out@*/ struct rpmlead * leadPtr, } if (hdrPtr == NULL) - headerFree(*hdr); + *hdr = headerFree(*hdr); return RPMRC_OK; } @@ -217,7 +217,7 @@ rpmRC rpmReadPackageHeader(FD_t fd, Header * hdrp, int * isSource, int * major, if (hdrp && *hdrp && sig) { headerMergeLegacySigs(*hdrp, sig); - headerFree(sig); + sig = rpmFreeSignature(sig); } if (isSource) *isSource = lead.type == RPMLEAD_SOURCE; @@ -147,8 +147,7 @@ void loadFi(Header h, TFI_t fi) fi->fstates = xcalloc(1, fi->fc * sizeof(*fi->fstates)); fi->dil = memcpy(xmalloc(fi->fc * sizeof(*fi->dil)), fi->dil, fi->fc * sizeof(*fi->dil)); - headerFree(fi->h); - fi->h = NULL; + fi->h = headerFree(fi->h); break; } @@ -167,7 +166,9 @@ void loadFi(Header h, TFI_t fi) fi->dperms = 0755; fi->fperms = 0644; + /*@-nullstate@*/ /* FIX: fi->h is NULL for TR_REMOVED */ return; + /*@=nullstate@*/ } void freeFi(TFI_t fi) @@ -209,9 +210,8 @@ void freeFi(TFI_t fi) fi->dil = hfd(fi->dil, -1); break; } - if (fi->h) { - headerFree(fi->h); fi->h = NULL; - } + + fi->h = headerFree(fi->h); /*@-nullstate@*/ return; @@ -569,7 +569,6 @@ static rpmRC chkdir (const char * dpath, const char * dname) return RPMRC_OK; } -/*@-compmempass@*/ rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd, const char ** specFilePtr, rpmCallbackFunction notify, rpmCallbackData notifyData, @@ -616,8 +615,7 @@ rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd, loadFi(h, fi); hge = fi->hge; hfd = (fi->hfd ? fi->hfd : headerFreeData); - headerFree(h); /* XXX reference held by transaction set */ - h = NULL; + h = headerFree(h); /* XXX reference held by transaction set */ (void) rpmInstallLoadMacros(fi, fi->h); @@ -627,7 +625,7 @@ rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd, if (cookie) { *cookie = NULL; - if (hge(h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL)) + if (hge(fi->h, RPMTAG_COOKIE, NULL, (void **) cookie, NULL)) *cookie = xstrdup(*cookie); } @@ -715,9 +713,11 @@ rpmRC rpmInstallSourcePackage(const char * rootDir, FD_t fd, psm->goal = PSM_PKGINSTALL; + /*@-compmempass@*/ /* FIX: psm->fi->dnl should be owned. */ rc = psmStage(psm, PSM_PROCESS); (void) psmStage(psm, PSM_FINI); + /*@=compmempass@*/ if (rc) rc = RPMRC_FAIL; @@ -730,8 +730,7 @@ exit: _specdir = _free(_specdir); _sourcedir = _free(_sourcedir); - if (h) - headerFree(h); + h = headerFree(h); if (fi) { freeFi(fi); @@ -742,7 +741,6 @@ exit: return rc; } -/*@=compmempass@*/ static char * SCRIPT_PATH = "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin"; @@ -1052,15 +1050,17 @@ static int handleOneTrigger(PSM_t psm, Header sourceH, Header triggeredH, int i; int skip; - if (!hge(triggeredH, RPMTAG_TRIGGERNAME, &tnt, - (void **) &triggerNames, &numTriggers)) + if (!( hge(triggeredH, RPMTAG_TRIGGERNAME, &tnt, + (void **) &triggerNames, &numTriggers) && + hge(triggeredH, RPMTAG_TRIGGERFLAGS, &tft, + (void **) &triggerFlags, NULL) && + hge(triggeredH, RPMTAG_TRIGGERVERSION, &tvt, + (void **) &triggerEVR, NULL)) + ) return 0; (void) headerNVR(sourceH, &sourceName, NULL, NULL); - (void) hge(triggeredH, RPMTAG_TRIGGERFLAGS, &tft, (void **) &triggerFlags, NULL); - (void) hge(triggeredH, RPMTAG_TRIGGERVERSION, &tvt, (void **) &triggerEVR, NULL); - for (i = 0; i < numTriggers; i++) { int_32 tit, tst, tpt; @@ -1084,12 +1084,14 @@ static int handleOneTrigger(PSM_t psm, Header sourceH, Header triggeredH, triggerEVR[i] + skip, triggerFlags[i])) continue; - (void) hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit, - (void **) &triggerIndices, NULL); - (void) hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst, - (void **) &triggerScripts, NULL); - (void) hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt, - (void **) &triggerProgs, NULL); + if (!( hge(triggeredH, RPMTAG_TRIGGERINDEX, &tit, + (void **) &triggerIndices, NULL) && + hge(triggeredH, RPMTAG_TRIGGERSCRIPTS, &tst, + (void **) &triggerScripts, NULL) && + hge(triggeredH, RPMTAG_TRIGGERSCRIPTPROG, &tpt, + (void **) &triggerProgs, NULL)) + ) + continue; (void) headerNVR(triggeredH, &triggerPackageName, NULL, NULL); @@ -1185,12 +1187,13 @@ static int runImmedTriggers(PSM_t psm) unsigned char * triggersRun; rpmRC rc = RPMRC_OK; - if (!hge(fi->h, RPMTAG_TRIGGERNAME, &tnt, - (void **) &triggerNames, &numTriggers)) + if (!( hge(fi->h, RPMTAG_TRIGGERNAME, &tnt, + (void **) &triggerNames, &numTriggers) && + hge(fi->h, RPMTAG_TRIGGERINDEX, &tit, + (void **) &triggerIndices, &numTriggerIndices)) + ) return 0; - (void) hge(fi->h, RPMTAG_TRIGGERINDEX, &tit, (void **) &triggerIndices, - &numTriggerIndices); triggersRun = alloca(sizeof(*triggersRun) * numTriggerIndices); memset(triggersRun, 0, sizeof(*triggersRun) * numTriggerIndices); @@ -1468,7 +1471,7 @@ assert(psm->mi == NULL); /* Write the signature section into the package. */ { Header sig = headerRegenSigHeader(fi->h); rc = rpmWriteSignature(psm->fd, sig); - headerFree(sig); + sig = rpmFreeSignature(sig); if (rc) break; } @@ -1615,11 +1618,9 @@ assert(psm->mi == NULL); if (psm->goal == PSM_PKGINSTALL) { int_32 installTime = time(NULL); - if (fi->fc > 0 && fi->fstates) - /*@-nullpass@*/ /* LCL: fi->fstates != NULL */ + if (fi->fstates != NULL && fi->fc > 0) (void) headerAddEntry(fi->h, RPMTAG_FILESTATES, RPM_CHAR_TYPE, fi->fstates, fi->fc); - /*@=nullpass@*/ (void) headerAddEntry(fi->h, RPMTAG_INSTALLTIME, RPM_INT32_TYPE, &installTime, 1); @@ -1627,8 +1628,10 @@ assert(psm->mi == NULL); if (ts->transFlags & RPMTRANS_FLAG_MULTILIB) { uint_32 multiLib, * newMultiLib, * p; - if (hge(fi->h, RPMTAG_MULTILIBS, NULL, (void **) &newMultiLib, NULL) && - hge(psm->oh, RPMTAG_MULTILIBS, NULL, (void **) &p, NULL)) + if (hge(fi->h, RPMTAG_MULTILIBS, NULL, + (void **) &newMultiLib, NULL) && + hge(psm->oh, RPMTAG_MULTILIBS, NULL, + (void **) &p, NULL)) { multiLib = *p; multiLib |= *newMultiLib; @@ -1721,14 +1724,9 @@ assert(psm->mi == NULL); (psm->pkgURL ? psm->pkgURL : "???")); } - if (fi->h && (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE)) { - headerFree(fi->h); - fi->h = NULL; - } - if (psm->oh) { - headerFree(psm->oh); - psm->oh = NULL; - } + if (fi->h && (psm->goal == PSM_PKGERASE || psm->goal == PSM_PKGSAVE)) + fi->h = headerFree(fi->h); + psm->oh = headerFree(psm->oh); psm->pkgURL = _free(psm->pkgURL); psm->rpmio_flags = _free(psm->rpmio_flags); psm->failedFile = _free(psm->failedFile); @@ -84,6 +84,7 @@ struct transactionFileInfo_s { /*@dependent@*/ struct availablePackage * ap; /*@owned@*/ struct sharedFileInfo * replaced; /*@owned@*/ uint_32 * replacedSizes; + /* for TR_REMOVED packages */ unsigned int record; }; diff --git a/lib/query.c b/lib/query.c index c74b69d01..26774d385 100644 --- a/lib/query.c +++ b/lib/query.c @@ -537,7 +537,7 @@ restart: /* Query a package file. */ if (rpmrc == RPMRC_OK) { retcode = showPackage(qva, rpmdb, h); - headerFree(h); + h = headerFree(h); continue; } diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 49340cd46..73b57c941 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -159,7 +159,7 @@ int rpmReSign(rpmResignFlags add, char * passPhrase, const char ** argv) /* Generate the new signatures */ if (add != RESIGN_ADD_SIGNATURE) { - rpmFreeSignature(sig); + sig = rpmFreeSignature(sig); sig = rpmNewSignature(); (void) rpmAddSignature(sig, sigtarget, RPMSIGTAG_SIZE, passPhrase); (void) rpmAddSignature(sig, sigtarget, RPMSIGTAG_MD5, passPhrase); @@ -213,10 +213,8 @@ exit: if (fd) (void) manageFile(&fd, NULL, 0, res); if (ofd) (void) manageFile(&ofd, NULL, 0, res); - if (sig) { - rpmFreeSignature(sig); - sig = NULL; - } + sig = rpmFreeSignature(sig); + if (sigtarget) { (void) unlink(sigtarget); sigtarget = _free(sigtarget); diff --git a/lib/rpminstall.c b/lib/rpminstall.c index f411506c0..7be27da73 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -403,7 +403,7 @@ restart: } mi = rpmdbFreeIterator(mi); if (count == 0) { - headerFree(h); + h = headerFree(h); continue; } /* Package is newer than those currently installed. */ @@ -412,7 +412,7 @@ restart: rc = rpmtransAddPackage(ts, h, NULL, fileName, (interfaceFlags & INSTALL_UPGRADE) != 0, relocations); - headerFree(h); /* XXX reference held by transaction set */ + h = headerFree(h); /* XXX reference held by transaction set */ if (defaultReloc) defaultReloc->oldPath = _free(defaultReloc->oldPath); diff --git a/lib/rpmlib.h b/lib/rpmlib.h index 74d979240..a6531a652 100644 --- a/lib/rpmlib.h +++ b/lib/rpmlib.h @@ -34,10 +34,10 @@ extern "C" { /** * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. * @param this memory to free - * @retval NULL always + * @return NULL always */ -/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this != NULL) free((void *)this); +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * p) { + if (p != NULL) free((void *)p); return NULL; } @@ -1674,8 +1674,10 @@ rpmVerifySignatureReturn rpmVerifySignature(const char *file, /** \ingroup signature * Destroy signature header from package. + * @param h signature header + * @return NULL always */ -void rpmFreeSignature(Header h); +/*@null@*/ Header rpmFreeSignature(/*@null@*/ /*@killref@*/ Header h); /* --- checksig/resign */ diff --git a/lib/signature.c b/lib/signature.c index 132b20258..1f004df4f 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -204,7 +204,7 @@ rpmRC rpmReadSignature(FD_t fd, Header * headerp, sigType sig_type) *headerp = h; /*@=nullderef@*/ else if (h) - headerFree(h); + h = headerFree(h); return rc; } @@ -235,9 +235,9 @@ Header rpmNewSignature(void) return h; } -void rpmFreeSignature(Header h) +Header rpmFreeSignature(Header h) { - headerFree(h); + return headerFree(h); } static int makePGPSignature(const char * file, /*@out@*/ void ** sig, diff --git a/lib/stringbuf.c b/lib/stringbuf.c index c4324d12b..3e6b58b41 100644 --- a/lib/stringbuf.c +++ b/lib/stringbuf.c @@ -26,10 +26,10 @@ struct StringBufRec { /** * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL. * @param this memory to free - * @retval NULL always + * @return NULL always */ -/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * this) { - if (this != NULL) free((void *)this); +/*@unused@*/ static inline /*@null@*/ void * _free(/*@only@*/ /*@null@*/ const void * p) { + if (p != NULL) free((void *)p); return NULL; } diff --git a/lib/transaction.c b/lib/transaction.c index c61ec3d93..3b4965e06 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -240,7 +240,7 @@ void rpmProblemSetFree(rpmProblemSet probs) for (i = 0; i < probs->numProblems; i++) { rpmProblem p = probs->probs + i; - if (p->h) headerFree(p->h); + p->h = headerFree(p->h); p->pkgNEVR = _free(p->pkgNEVR); p->altNEVR = _free(p->altNEVR); p->str1 = _free(p->str1); @@ -1414,11 +1414,11 @@ static /*@dependent@*/ struct availablePackage * tsGetAlp(void * this) { /** * Destroy transaction element iterator. * @param this transaction element iterator - * @retval NULL always + * @return NULL always */ static /*@null@*/ void * tsFreeIterator(/*@only@*//*@null@*/ const void * this) { - return _free((void *)this); + return _free(this); } /** @@ -1886,13 +1886,16 @@ int rpmRunTransactions( rpmTransactionSet ts, * If unfiltered problems exist, free memory and return. */ if ((ts->transFlags & RPMTRANS_FLAG_BUILD_PROBS) || - (ts->probs->numProblems && (!okProbs || psTrim(okProbs, ts->probs)))) { + (ts->probs->numProblems && (!okProbs || psTrim(okProbs, ts->probs)))) + { *newProbs = ts->probs; for (alp = ts->addedPackages.list, fi = ts->flList; - (alp - ts->addedPackages.list) < ts->addedPackages.size; - alp++, fi++) { - headerFree(hdrs[alp - ts->addedPackages.list]); + (alp - ts->addedPackages.list) < ts->addedPackages.size; + alp++, fi++) + { + hdrs[alp - ts->addedPackages.list] = + headerFree(hdrs[alp - ts->addedPackages.list]); } ts->flList = freeFl(ts, ts->flList); @@ -1946,8 +1949,7 @@ assert(alp == fi->ap); Header h; rpmRC rpmrc; - headerFree(hdrs[i]); - hdrs[i] = NULL; + hdrs[i] = headerFree(hdrs[i]); rpmrc = rpmReadPackageHeader(alp->fd, &h, NULL, NULL, NULL); if (!(rpmrc == RPMRC_OK || rpmrc == RPMRC_BADSIZE)) { (void)ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, @@ -1956,7 +1958,7 @@ assert(alp == fi->ap); ourrc++; } else { hdrs[i] = relocateFileList(ts, fi, alp, h, NULL); - headerFree(h); + h = headerFree(h); } if (alp->fd) gotfd = 1; } @@ -1967,7 +1969,7 @@ assert(alp == fi->ap); if (fi->h) { hsave = headerLink(fi->h); - headerFree(fi->h); + fi->h = headerFree(fi->h); } fi->h = headerLink(hdrs[i]); if (alp->multiLib) @@ -1978,18 +1980,17 @@ assert(alp == fi->ap); ourrc++; lastFailed = i; } - headerFree(fi->h); - fi->h = NULL; + fi->h = headerFree(fi->h); if (hsave) { fi->h = headerLink(hsave); - headerFree(hsave); + hsave = headerFree(hsave); } } else { ourrc++; lastFailed = i; } - headerFree(hdrs[i]); + hdrs[i] = headerFree(hdrs[i]); if (gotfd) { (void)ts->notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0, diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c index 8d8b76830..cfaa5d9a5 100644 --- a/rpmdb/rpmdb.c +++ b/rpmdb/rpmdb.c @@ -1046,7 +1046,7 @@ static int rpmdbFindByFile(rpmdb rpmdb, /*@null@*/ const char * filespec, baseNames = hfd(baseNames, bnt); dirNames = hfd(dirNames, dnt); - headerFree(h); + h = headerFree(h); } rec = _free(rec); @@ -1172,7 +1172,7 @@ static int dbiFindMatches(dbiIndex dbi, DBC * dbcursor, } else (*matches)->recs[i].hdrNum = 0; - headerFree(h); + h = headerFree(h); } if (gotMatches) { @@ -1310,8 +1310,7 @@ rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi) if (dbi && mi->mi_dbc && mi->mi_modified && mi->mi_prevoffset) { xx = dbiUpdateRecord(dbi, mi->mi_dbc, mi->mi_prevoffset, mi->mi_h); } - headerFree(mi->mi_h); - mi->mi_h = NULL; + mi->mi_h = headerFree(mi->mi_h); } if (dbi) { if (dbi->dbi_rmw) @@ -1472,8 +1471,7 @@ if (dbi->dbi_api == 1 && dbi->dbi_rpmtag == RPMDBI_PACKAGES && rc == EFAULT) { if (mi->mi_h) { if (mi->mi_modified && mi->mi_prevoffset) (void)dbiUpdateRecord(dbi, mi->mi_dbc, mi->mi_prevoffset, mi->mi_h); - headerFree(mi->mi_h); - mi->mi_h = NULL; + mi->mi_h = headerFree(mi->mi_h); } /* Is this the end of the iteration? */ @@ -1892,7 +1890,7 @@ int rpmdbRemove(rpmdb rpmdb, int rid, unsigned int hdrNum) unblockSignals(rpmdb, &signalMask); - headerFree(h); + h = headerFree(h); return 0; } @@ -2628,8 +2626,7 @@ int rpmdbRebuild(const char * rootdir) { Header nh = (headerIsEntry(h, RPMTAG_HEADERIMAGE) ? headerCopy(h) : NULL); rc = rpmdbAdd(newdb, -1, (nh ? nh : h)); - if (nh) - headerFree(nh); + nh = headerFree(nh); } if (rc) { |