diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-06-23 17:50:08 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-06-23 17:50:08 +0300 |
commit | 51520de1d3dffedc0c047b6da3fa68e98c92acc0 (patch) | |
tree | 0ae38be18e8e3201be251b5df0b7b134e24c0219 /lib/header.c | |
parent | b02893092594b868296c5b3f58ab631e368bae1a (diff) | |
download | rpm-51520de1d3dffedc0c047b6da3fa68e98c92acc0.tar.gz rpm-51520de1d3dffedc0c047b6da3fa68e98c92acc0.tar.bz2 rpm-51520de1d3dffedc0c047b6da3fa68e98c92acc0.zip |
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
Diffstat (limited to 'lib/header.c')
-rw-r--r-- | lib/header.c | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/lib/header.c b/lib/header.c index 8cac9758e..e89de64e8 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; } |