diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-07-09 13:39:55 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-07-09 13:39:55 +0300 |
commit | 6ffeec9d7f57ebb520d15581d55555244c0f3058 (patch) | |
tree | 7b098208b7452d73bb4971f4acdcc84026a23229 /lib/rpmps.c | |
parent | cb8241dda783f7e8c143b08fecf57fe89a39c3a6 (diff) | |
download | rpm-6ffeec9d7f57ebb520d15581d55555244c0f3058.tar.gz |
Add reference counting to rpmProblems
Diffstat (limited to 'lib/rpmps.c')
-rw-r--r-- | lib/rpmps.c | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/rpmps.c b/lib/rpmps.c index 6f059c705..615d70db5 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; } |