summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-03-31 09:25:18 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-03-31 09:25:18 +0300
commit58afc25abb0ebb7826c00b688fb1825d5b0087c0 (patch)
tree1006a843dd4920c6ecd286a648e287c5ed304032
parented07bf20d3bffaa4d99b4b6db2460b1046d7ead3 (diff)
downloadlibrpm-tizen-58afc25abb0ebb7826c00b688fb1825d5b0087c0.tar.gz
librpm-tizen-58afc25abb0ebb7826c00b688fb1825d5b0087c0.tar.bz2
librpm-tizen-58afc25abb0ebb7826c00b688fb1825d5b0087c0.zip
Copy N + EVR into ds in rpmdsSingle() instead of just referring
- previously a ds created by rpmdsSingle() would turn invalid as soon as the N and EVR strings were freed by caller (or went out of scope), ick - convert the N + EVR strings passed to rpmdsSingle() to similar construct as is returned by headerGetEntry so headerFreeData will free both the pointers + contents.
-rw-r--r--lib/rpmds.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/rpmds.c b/lib/rpmds.c
index ac88e756b..daebcbe70 100644
--- a/lib/rpmds.c
+++ b/lib/rpmds.c
@@ -82,6 +82,22 @@ static int dsType(rpmTag tag,
return rc;
}
+/*
+ * Dupe a string into string array (of size 1) + contents stored in a single
+ * allocation block similarly to how headerGetEntry returns data so it will
+ * be freed by headerFreeData().
+ */
+static const char ** str2hge(const char *str)
+{
+ const char ** arr;
+ char *t = xmalloc(sizeof(*arr) + strlen(str) + 1);
+ arr = (const char **) t;
+ t += sizeof(*arr);
+ strcpy(t, str);
+ arr[0] = t;
+ return arr;
+}
+
rpmds rpmdsUnlink(rpmds ds, const char * msg)
{
if (ds == NULL) return NULL;
@@ -311,12 +327,12 @@ rpmds rpmdsSingle(rpmTag tagN, const char * N, const char * EVR, rpmsenseFlags F
ds->BT = now;
}
ds->Count = 1;
- ds->N = xmalloc(sizeof(*ds->N));
- ds->N[0] = N;
+
+ ds->N = str2hge(N);
ds->Nt = RPM_FORCEFREE_TYPE; /* XXX to insure that hfd will free */
- ds->EVR = xmalloc(sizeof(*ds->EVR));
- ds->EVR[0] = EVR;
+ ds->EVR = str2hge(EVR);
ds->EVRt = RPM_FORCEFREE_TYPE; /* XXX to insure that hfd will free */
+
ds->Flags = xmalloc(sizeof(*ds->Flags));
ds->Flags[0] = Flags;
ds->i = 0;