Skip to content

Commit

Permalink
Natively allocate bunch of miscellaneous librpm structs
Browse files Browse the repository at this point in the history
These have nothing in common except "miscellaneous structs
allocated by calloc/free", and that they have lots of data to
consider moving to native data types but not just now.
  • Loading branch information
pmatilai committed Apr 30, 2024
1 parent b287bdc commit 87b5627
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions lib/cpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ rpmcpio_t rpmcpioOpen(FD_t fd, char mode)
(mode & O_ACCMODE) != O_WRONLY)
return NULL;

rpmcpio_t cpio = (rpmcpio_t)xcalloc(1, sizeof(*cpio));
rpmcpio_t cpio = new rpmcpio_s {};
cpio->fd = fdLink(fd);
cpio->mode = mode;
cpio->offset = 0;
Expand Down Expand Up @@ -460,7 +460,7 @@ rpmcpio_t rpmcpioFree(rpmcpio_t cpio)
if (cpio) {
if (cpio->fd)
(void) rpmcpioClose(cpio);
free(cpio);
delete cpio;
}
return NULL;
}
5 changes: 2 additions & 3 deletions lib/psm.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,7 @@ static rpmpsm rpmpsmFree(rpmpsm psm)
rpmfilesFree(psm->files);
rpmtsFree(psm->ts),
/* XXX rpmte not refcounted yet */
memset(psm, 0, sizeof(*psm)); /* XXX trash and burn */
free(psm);
delete psm;
}
return NULL;
}
Expand All @@ -615,7 +614,7 @@ static int isUpdate(rpmts ts, rpmte te)

static rpmpsm rpmpsmNew(rpmts ts, rpmte te, pkgGoal goal)
{
rpmpsm psm = (rpmpsm)xcalloc(1, sizeof(*psm));
rpmpsm psm = new rpmpsm_s {};
psm->ts = rpmtsLink(ts);
psm->files = rpmteFiles(te);
psm->te = te; /* XXX rpmte not refcounted yet */
Expand Down
6 changes: 2 additions & 4 deletions lib/rpmgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,14 @@ rpmgi rpmgiFree(rpmgi gi)
if (gi != NULL) {
rpmtsFree(gi->ts);
argvFree(gi->argv);

memset(gi, 0, sizeof(*gi)); /* XXX trash and burn */
free(gi);
delete gi;
}
return NULL;
}

rpmgi rpmgiNew(rpmts ts, rpmgiFlags flags, ARGV_const_t argv)
{
rpmgi gi = (rpmgi)xcalloc(1, sizeof(*gi));
rpmgi gi = new rpmgi_s {};

gi->ts = rpmtsLink(ts);

Expand Down
6 changes: 3 additions & 3 deletions lib/rpmlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct rpmlock_s {

static rpmlock rpmlock_new(const char *lock_path, const char *descr)
{
rpmlock lock = (rpmlock) malloc(sizeof(*lock));
rpmlock lock = new rpmlock_s {};

if (lock != NULL) {
mode_t oldmask = umask(022);
Expand All @@ -35,7 +35,7 @@ static rpmlock rpmlock_new(const char *lock_path, const char *descr)
if (errno == EACCES)
lock->fd = open(lock_path, O_RDONLY);
if (lock->fd == -1) {
free(lock);
delete lock;
lock = NULL;
} else {
lock->openmode = RPMLOCK_READ;
Expand All @@ -58,7 +58,7 @@ static void rpmlock_free(rpmlock lock)
free(lock->path);
free(lock->descr);
(void) close(lock->fd);
free(lock);
delete lock;
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/rpmscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ static rpmScript rpmScriptNew(Header h, rpmTagVal tag, const char *body,
rpmscriptFlags flags, const char *prefix)
{
char *nevra = headerGetAsString(h, RPMTAG_NEVRA);
rpmScript script = (rpmScript)xcalloc(1, sizeof(*script));
rpmScript script = new rpmScript_s {};
script->tag = tag;
script->type = getScriptType(tag);
script->flags = getDefFlags(tag) | flags;
Expand Down Expand Up @@ -553,7 +553,7 @@ static rpmScript rpmScriptNew(Header h, rpmTagVal tag, const char *body,
void rpmScriptSetNextFileFunc(rpmScript script, nextfilefunc func,
void *param)
{
script->nextFileFunc = (struct scriptNextFileFunc_s *)xmalloc(sizeof(*script->nextFileFunc));
script->nextFileFunc = new scriptNextFileFunc_s {};
script->nextFileFunc->func = func;
script->nextFileFunc->param = param;
}
Expand Down Expand Up @@ -706,8 +706,8 @@ rpmScript rpmScriptFree(rpmScript script)
free(script->args);
free(script->body);
free(script->descr);
free(script->nextFileFunc);
free(script);
delete script->nextFileFunc;
delete script;
}
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/rpmvs.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ void rpmvsAppendTag(struct rpmvs_s *vs, hdrblob blob, rpmTagVal tag)

struct rpmvs_s *rpmvsCreate(int vfylevel, rpmVSFlags vsflags, rpmKeyring keyring)
{
struct rpmvs_s *sis = (struct rpmvs_s *)xcalloc(1, sizeof(*sis));
struct rpmvs_s *sis = new rpmvs_s {};
sis->vsflags = vsflags;
sis->keyring = rpmKeyringLink(keyring);
sis->vfylevel = vfylevel;
Expand Down Expand Up @@ -387,7 +387,7 @@ struct rpmvs_s *rpmvsFree(struct rpmvs_s *sis)
rpmsinfoFini(&sis->sigs[i]);
}
free(sis->sigs);
free(sis);
delete sis;
}
return NULL;
}
Expand Down

0 comments on commit 87b5627

Please sign in to comment.