diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-03-11 17:14:25 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-03-11 18:06:33 +0200 |
commit | d05e4438a9efa5ad2cf0ecfef1b4537c37e132d4 (patch) | |
tree | b9c4e5598a370ffaae4aac3e0c0cd59924a0a859 /rpmio | |
parent | 31288616ce442203df626ef0a49ebc3893258fc9 (diff) | |
download | rpm-d05e4438a9efa5ad2cf0ecfef1b4537c37e132d4.tar.gz rpm-d05e4438a9efa5ad2cf0ecfef1b4537c37e132d4.tar.bz2 rpm-d05e4438a9efa5ad2cf0ecfef1b4537c37e132d4.zip |
Streamline rpmDigestInit() a bit
- single point of exit, rearrange to avoid having to free if stuff fails
Diffstat (limited to 'rpmio')
-rw-r--r-- | rpmio/digest.c | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/rpmio/digest.c b/rpmio/digest.c index c565cf608..d13d7757f 100644 --- a/rpmio/digest.c +++ b/rpmio/digest.c @@ -74,30 +74,27 @@ rpmDigestLength(pgpHashAlgo hashalgo) DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags) { - HASH_HashType type; - DIGEST_CTX ctx; + HASH_HashType type = getHashType(hashalgo); + HASHContext *hashctx = NULL; + DIGEST_CTX ctx = NULL; if (rpmInitCrypto() < 0) - return NULL; - - ctx = xcalloc(1, sizeof(*ctx)); - ctx->flags = flags; + goto exit; type = getHashType(hashalgo); if (type == HASH_AlgNULL) { - free(ctx); - return NULL; + goto exit; } - ctx->hashctx = HASH_Create(type); - if (ctx->hashctx == NULL) { - free(ctx); - return NULL; + if ((hashctx = HASH_Create(type)) != NULL) { + ctx = xcalloc(1, sizeof(*ctx)); + ctx->flags = flags; + ctx->hashctx = hashctx; + HASH_Begin(ctx->hashctx); } - - HASH_Begin(ctx->hashctx); DPRINTF((stderr, "*** Init(%x) ctx %p hashctx %p\n", flags, ctx, ctx->hashctx)); +exit: return ctx; } |