From 0b0dcd114028e1e2a00870917cf07a27858a30b1 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 9 Apr 2008 13:54:39 +0300 Subject: [PATCH] Replace alloca+memset with xcalloc() in rpmdbRemove() - return value is suspect: should return "ret" instead of 0 at exit depending on what happened in removal but preserving previous behavior for now... --- rpmdb/rpmdb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/rpmdb/rpmdb.c b/rpmdb/rpmdb.c index 8aafa13..25d987d 100644 --- a/rpmdb/rpmdb.c +++ b/rpmdb/rpmdb.c @@ -2391,8 +2391,8 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, rpmRC (*hdrchk) (rpmts ts, const void *uh, size_t uc, char ** msg)) { DBC * dbcursor = NULL; - DBT * key = alloca(sizeof(*key)); - DBT * data = alloca(sizeof(*data)); + DBT * key; + DBT * data; union _dbswap mi_offset; HGE_t hge = (HGE_t)headerGetEntryMinMemory; HFD_t hfd = headerFreeData; @@ -2404,8 +2404,8 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, if (db == NULL) return 0; - memset(key, 0, sizeof(*key)); - memset(data, 0, sizeof(*data)); + key = xcalloc(1, sizeof(*key)); + data = xcalloc(1, sizeof(*data)); { rpmdbMatchIterator mi; mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, &hdrNum, sizeof(hdrNum)); @@ -2418,7 +2418,8 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, if (h == NULL) { rpmlog(RPMLOG_ERR, _("%s: cannot read header at 0x%x\n"), "rpmdbRemove", hdrNum); - return 1; + ret = 1; + goto exit; } { @@ -2660,7 +2661,12 @@ int rpmdbRemove(rpmdb db, int rid, unsigned int hdrNum, h = headerFree(h); /* XXX return ret; */ - return 0; + ret = 0; + +exit: + free(key); + free(data); + return ret; } /* XXX install.c */ -- 2.7.4