From 51520de1d3dffedc0c047b6da3fa68e98c92acc0 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 23 Jun 2009 17:50:08 +0300 Subject: [PATCH] Set HEADERFLAGS_ALLOCATED centrally from headerLoad() - requiring every caller to handle this separately, violating header type opaqueness in the process, doesn't seem that bright an idea - also fix a memleak on signature header read in case of failure --- lib/header.c | 19 ++++++------------- lib/package.c | 1 - lib/rpmdb.c | 4 +--- lib/signature.c | 3 ++- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/lib/header.c b/lib/header.c index 8cac975..e89de64 100644 --- a/lib/header.c +++ b/lib/header.c @@ -966,6 +966,7 @@ Header headerLoad(void * uh) h->flags &= ~HEADERFLAG_SORTED; headerSort(h); + h->flags |= HEADERFLAG_ALLOCATED; return h; @@ -991,9 +992,6 @@ Header headerReload(Header h, rpmTag tag) uh = _free(uh); return NULL; } - if (nh->flags & HEADERFLAG_ALLOCATED) - uh = _free(uh); - nh->flags |= HEADERFLAG_ALLOCATED; if (ENTRY_IS_REGION(nh->index)) { if (tag == HEADER_SIGNATURES || tag == HEADER_IMMUTABLE) nh->index[0].info.tag = tag; @@ -1014,11 +1012,9 @@ Header headerCopyLoad(const void * uh) /* Sanity checks on header intro. */ if (!(hdrchkTags(il) || hdrchkData(dl)) && pvlen < headerMaxbytes) { nuh = memcpy(xmalloc(pvlen), uh, pvlen); - if ((h = headerLoad(nuh)) != NULL) - h->flags |= HEADERFLAG_ALLOCATED; + if ((h = headerLoad(nuh)) == NULL) + nuh = _free(nuh); } - if (h == NULL) - nuh = _free(nuh); return h; } @@ -1079,12 +1075,9 @@ Header headerRead(FD_t fd, enum hMagic magicp) h = headerLoad(ei); exit: - if (h) { - if (h->flags & HEADERFLAG_ALLOCATED) - ei = _free(ei); - h->flags |= HEADERFLAG_ALLOCATED; - } else if (ei) - ei = _free(ei); + if (h == NULL && ei != NULL) { + free(ei); + } return h; } diff --git a/lib/package.c b/lib/package.c index ebb1135..6cff7c1 100644 --- a/lib/package.c +++ b/lib/package.c @@ -511,7 +511,6 @@ static rpmRC rpmpkgReadHeader(rpmKeyring keyring, rpmVSFlags vsflags, rc = RPMRC_FAIL; goto exit; } - h->flags |= HEADERFLAG_ALLOCATED; ei = NULL; /* XXX will be freed with header */ exit: diff --git a/lib/rpmdb.c b/lib/rpmdb.c index d76630e..1f035bf 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -29,7 +29,7 @@ #include "lib/rpmdb_internal.h" #include "lib/fprint.h" -#include "lib/header_internal.h" /* XXX for HEADERFLAG_ALLOCATED */ +#include "lib/header_internal.h" /* XXX for headerSetInstance() */ #include "debug.h" int _rpmdb_debug = 0; @@ -2097,8 +2097,6 @@ top: /* Did the header blob load correctly? */ #if !defined(_USE_COPY_LOAD) mi->mi_h = headerLoad(uh); - if (mi->mi_h) - mi->mi_h->flags |= HEADERFLAG_ALLOCATED; #else mi->mi_h = headerCopyLoad(uh); #endif diff --git a/lib/signature.c b/lib/signature.c index 808bce7..a6d1efd 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -236,7 +236,6 @@ rpmRC rpmReadSignature(FD_t fd, Header * sighp, sigType sig_type, char ** msg) rasprintf(&buf, _("sigh load: BAD\n")); goto exit; } - sigh->flags |= HEADERFLAG_ALLOCATED; { size_t sigSize = headerSizeof(sigh, HEADER_MAGIC_YES); size_t pad = (8 - (sigSize % 8)) % 8; /* 8-byte pad */ @@ -267,11 +266,13 @@ rpmRC rpmReadSignature(FD_t fd, Header * sighp, sigType sig_type, char ** msg) goto exit; } } + ei = NULL; /* XXX will be freed with header */ exit: if (sighp && sigh && rc == RPMRC_OK) *sighp = headerLink(sigh); sigh = headerFree(sigh); + free(ei); if (msg != NULL) { *msg = buf; -- 2.7.4