diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2016-11-23 10:21:32 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2016-11-23 11:06:48 +0200 |
commit | ca407bf38ec83b6b991537233963a14b79a5821e (patch) | |
tree | c2aee6b029ceccc79970e34d3467ac00fbcbef28 | |
parent | b80f81678db380ca6cd5069ed20bd029a5951329 (diff) | |
download | rpm-ca407bf38ec83b6b991537233963a14b79a5821e.tar.gz |
Add a helper function for importing an already read hdrblob
Doesn't really reduce code that much but frees callers from having
to worry about freeing allocations from the blob.
-rw-r--r-- | lib/header.c | 15 | ||||
-rw-r--r-- | lib/header_internal.h | 4 | ||||
-rw-r--r-- | lib/package.c | 9 | ||||
-rw-r--r-- | lib/signature.c | 6 |
4 files changed, 21 insertions, 13 deletions
diff --git a/lib/header.c b/lib/header.c index 9089b970f..cc90496a4 100644 --- a/lib/header.c +++ b/lib/header.c @@ -2044,3 +2044,18 @@ exit: return rc; } +rpmRC hdrblobImport(hdrblob blob, headerImportFlags flags, + Header *hdrp, char **emsg) +{ + Header h = headerImport(blob->ei, blob->uc, flags); + + if (h == NULL) { + free(blob->ei); + rasprintf(emsg, _("hdr load: BAD")); + } else { + *hdrp = h; + } + blob->ei = NULL; + + return (h != NULL) ? RPMRC_OK : RPMRC_FAIL; +} diff --git a/lib/header_internal.h b/lib/header_internal.h index e671a9f2d..76d1bd528 100644 --- a/lib/header_internal.h +++ b/lib/header_internal.h @@ -56,6 +56,10 @@ rpmRC hdrblobInit(const void *uh, size_t uc, RPM_GNUC_INTERNAL rpmRC hdrblobRead(FD_t fd, int magic, int exact_size, rpmTagVal regionTag, hdrblob blob, char **emsg); +RPM_GNUC_INTERNAL +rpmRC hdrblobImport(hdrblob blob, headerImportFlags flags, + Header *hdrp, char **emsg); + /** \ingroup header * Set header instance (rpmdb record number) * @param h header diff --git a/lib/package.c b/lib/package.c index 54e6aa042..0f694505e 100644 --- a/lib/package.c +++ b/lib/package.c @@ -263,14 +263,7 @@ static rpmRC rpmpkgReadHeader(FD_t fd, Header *hdrp, char ** msg) goto exit; /* OK, blob looks sane, load the header. */ - h = headerImport(blob.ei, blob.uc, 0); - if (h == NULL) { - free(blob.ei); - free(buf); - rasprintf(&buf, _("hdr load: BAD")); - goto exit; - } - rc = RPMRC_OK; + rc = hdrblobImport(&blob, 0, &h, &buf); exit: if (hdrp && h && rc == RPMRC_OK) diff --git a/lib/signature.c b/lib/signature.c index 96a5fc90e..a01f286cb 100644 --- a/lib/signature.c +++ b/lib/signature.c @@ -161,12 +161,8 @@ rpmRC rpmReadSignature(FD_t fd, Header * sighp, char ** msg) goto exit; /* OK, blob looks sane, load the header. */ - sigh = headerImport(blob.ei, blob.uc, 0); - if (sigh == NULL) { - rasprintf(&buf, _("sigh load: BAD")); - free(blob.ei); + if (hdrblobImport(&blob, 0, &sigh, &buf) != RPMRC_OK) goto exit; - } /* XXX the padding calculation here is only for debug printing */ { size_t sigSize = headerSizeof(sigh, HEADER_MAGIC_YES); |