From: Panu Matilainen Date: Thu, 9 Jul 2009 10:39:55 +0000 (+0300) Subject: Add reference counting to rpmProblems X-Git-Tag: rpm-4.8.0-beta1~418 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ffeec9d7f57ebb520d15581d55555244c0f3058;p=platform%2Fupstream%2Frpm.git Add reference counting to rpmProblems --- diff --git a/lib/rpmps.c b/lib/rpmps.c index 6f059c7..615d70d 100644 --- a/lib/rpmps.c +++ b/lib/rpmps.c @@ -21,6 +21,7 @@ struct rpmProblem_s { int ignoreProblem; char * str1; uint64_t num1; + int nrefs; }; /** @@ -149,7 +150,7 @@ void rpmpsAppendProblem(rpmps ps, rpmProblem prob) p = ps->probs + ps->numProblems; ps->numProblems++; - *p = prob; + *p = rpmProblemLink(prob); } void rpmpsAppend(rpmps ps, rpmProblemType type, @@ -162,6 +163,7 @@ void rpmpsAppend(rpmps ps, rpmProblemType type, p = rpmProblemCreate(type, pkgNEVR, key, dn, bn, altNEVR, number); rpmpsAppendProblem(ps, p); + rpmProblemFree(p); } #define XSTRCMP(a, b) ((!(a) && !(b)) || ((a) && (b) && !strcmp((a), (b)))) @@ -236,15 +238,36 @@ rpmProblem rpmProblemCreate(rpmProblemType type, if (dn != NULL) t = stpcpy(t, dn); if (bn != NULL) t = stpcpy(t, bn); } - return p; + return rpmProblemLink(p); } rpmProblem rpmProblemFree(rpmProblem prob) { + if (prob == NULL) return NULL; + + if (prob->nrefs > 1) { + return rpmProblemUnlink(prob); + } prob->pkgNEVR = _free(prob->pkgNEVR); prob->altNEVR = _free(prob->altNEVR); prob->str1 = _free(prob->str1); - prob = _free(prob); + free(prob); + return NULL; +} + +rpmProblem rpmProblemLink(rpmProblem prob) +{ + if (prob) { + prob->nrefs++; + } + return prob; +} + +rpmProblem rpmProblemUnlink(rpmProblem prob) +{ + if (prob) { + prob->nrefs--; + } return NULL; } diff --git a/lib/rpmps.h b/lib/rpmps.h index 0fc800d..26f4264 100644 --- a/lib/rpmps.h +++ b/lib/rpmps.h @@ -86,6 +86,20 @@ rpmProblem rpmProblemCreate(rpmProblemType type, rpmProblem rpmProblemFree(rpmProblem prob); /** \ingroup rpmps + * Reference an rpmProblem instance + * @param prob rpm problem + * @return rpm problem + */ +rpmProblem rpmProblemLink(rpmProblem prob); + +/** \ingroup rpmps + * Unreference an rpmProblem instance + * @param prob rpm problem + * @return rpm problem + */ +rpmProblem rpmProblemUnlink(rpmProblem prob); + +/** \ingroup rpmps * Return package NEVR * @param prob rpm problem * @return package NEVR