Skip to content

Commit

Permalink
Natively allocate rpmds, rpmfiles and rpmfi mains structs
Browse files Browse the repository at this point in the history
Each of these contains mountains of data allocated from headerGet()
so we can't easily convert them to STL containers.
  • Loading branch information
pmatilai committed Apr 30, 2024
1 parent 930942d commit 22a4c32
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions lib/rpmds.c
Expand Up @@ -241,16 +241,15 @@ rpmds rpmdsFree(rpmds ds)
ds->Color = _free(ds->Color);

(void) rpmdsUnlink(ds);
memset(ds, 0, sizeof(*ds)); /* XXX trash and burn */
ds = _free(ds);
delete ds;
return NULL;
}

static rpmds rpmdsCreate(rpmstrPool pool,
rpmTagVal tagN, const char * Type, int Count,
unsigned int instance)
{
rpmds ds = (rpmds)xcalloc(1, sizeof(*ds));
rpmds ds = new rpmds_s {};

ds->pool = (pool != NULL) ? rpmstrPoolLink(pool) : rpmstrPoolCreate();
ds->tagN = tagN;
Expand Down
13 changes: 6 additions & 7 deletions lib/rpmfi.c
Expand Up @@ -1242,7 +1242,7 @@ rpmfiles rpmfilesFree(rpmfiles fi)
if (rpmfilesFC(fi) > 0) {
if (fi->ofndata != &fi->fndata) {
rpmfnClear(fi->ofndata);
free(fi->ofndata);
delete fi->ofndata;
}
rpmfnClear(&fi->fndata);

Expand Down Expand Up @@ -1291,8 +1291,7 @@ rpmfiles rpmfilesFree(rpmfiles fi)
fi->nlinks = nlinkHashFree(fi->nlinks);

(void) rpmfilesUnlink(fi);
memset(fi, 0, sizeof(*fi)); /* XXX trash and burn */
fi = _free(fi);
delete fi;

return NULL;
}
Expand All @@ -1310,7 +1309,7 @@ rpmfi rpmfiFree(rpmfi fi)
fi->found = _free(fi->found);
fi->archive = rpmcpioFree(fi->archive);

free(fi);
delete fi;
return NULL;
}

Expand Down Expand Up @@ -1709,7 +1708,7 @@ static int rpmfilesPopulate(rpmfiles fi, Header h, rpmfiFlags flags)

rpmfiles rpmfilesNew(rpmstrPool pool, Header h, rpmTagVal tagN, rpmfiFlags flags)
{
rpmfiles fi = (rpmfiles)xcalloc(1, sizeof(*fi));
rpmfiles fi = new rpmfiles_s {};
int fc;

fi->magic = RPMFIMAGIC;
Expand All @@ -1732,7 +1731,7 @@ rpmfiles rpmfilesNew(rpmstrPool pool, Header h, rpmTagVal tagN, rpmfiFlags flags
if (headerIsEntry(h, RPMTAG_ORIGBASENAMES)) {
/* For relocated packages, grab the original paths too */
int ofc;
fi->ofndata = (rpmfn)xmalloc(sizeof(*fi->ofndata));
fi->ofndata = new rpmfn_s {};
ofc = rpmfnInit(fi->ofndata, RPMTAG_ORIGBASENAMES, h, fi->pool);

if (ofc != 0 && ofc != fc)
Expand Down Expand Up @@ -1780,7 +1779,7 @@ static rpmfi initIter(rpmfiles files, int itype, int link)
rpmfi fi = NULL;

if (files && itype>=0 && itype<=RPMFILEITERMAX) {
fi = (rpmfi)xcalloc(1, sizeof(*fi));
fi = new rpmfi_s {};
fi->i = -1;
fi->j = -1;
fi->files = link ? rpmfilesLink(files) : files;
Expand Down

0 comments on commit 22a4c32

Please sign in to comment.