aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--URPM.xs32
1 files changed, 18 insertions, 14 deletions
diff --git a/URPM.xs b/URPM.xs
index ebc0370..4468c8c 100644
--- a/URPM.xs
+++ b/URPM.xs
@@ -50,7 +50,6 @@ struct s_Package {
struct s_Transaction {
rpmts ts;
- int count;
};
struct s_TransactionData {
@@ -1230,6 +1229,7 @@ update_header(char *filename, URPM__Package pkg, int keep_all_tags, int vsflags)
}
return 1;
}
+ rpmtsFree(ts);
} else if (sig[0] == 0x8e && sig[1] == 0xad && sig[2] == 0xe8 && sig[3] == 0x01) {
FD_t fd = fdDup(d);
@@ -2632,9 +2632,13 @@ Db_open(prefix="", write_perm=0)
read_config_files(0);
db = malloc(sizeof(struct s_Transaction));
db->ts = rpmtsCreate();
- db->count = 1;
rpmtsSetRootDir(db->ts, prefix);
- RETVAL = rpmtsOpenDB(db->ts, write_perm ? O_RDWR | O_CREAT : O_RDONLY) == 0 ? db : NULL;
+ if (rpmtsOpenDB(db->ts, write_perm ? O_RDWR | O_CREAT : O_RDONLY) == 0) {
+ RETVAL = db;
+ } else {
+ RETVAL = NULL;
+ rpmtsFree(db->ts);
+ }
OUTPUT:
RETVAL
@@ -2656,10 +2660,8 @@ void
Db_DESTROY(db)
URPM::DB db
CODE:
- if (--db->count <= 0) {
- rpmtsFree(db->ts);
- free(db);
- }
+ rpmtsFree(db->ts);
+ free(db);
int
Db_traverse(db,callback)
@@ -2670,6 +2672,7 @@ Db_traverse(db,callback)
rpmdbMatchIterator mi;
int count = 0;
CODE:
+ db->ts = rpmtsLink(db->ts, "URPM::DB::traverse");
mi = rpmtsInitIterator(db->ts, RPMDBI_PACKAGES, NULL, 0);
while ((header = rpmdbNextIterator(mi))) {
if (SvROK(callback)) {
@@ -2691,6 +2694,7 @@ Db_traverse(db,callback)
++count;
}
rpmdbFreeIterator(mi);
+ rpmtsFree(db->ts);
RETVAL = count;
OUTPUT:
RETVAL
@@ -2731,6 +2735,7 @@ Db_traverse_tag(db,tag,names,callback)
STRLEN str_len;
SV **isv = av_fetch(names_av, i, 0);
char *name = SvPV(*isv, str_len);
+ db->ts = rpmtsLink(db->ts, "URPM::DB::traverse_tag");
mi = rpmtsInitIterator(db->ts, rpmtag, name, str_len);
while ((header = rpmdbNextIterator(mi))) {
if (SvROK(callback)) {
@@ -2753,6 +2758,7 @@ Db_traverse_tag(db,tag,names,callback)
}
rpmdbFreeIterator(mi);
}
+ rpmtsFree(db->ts);
} else croak("bad arguments list");
RETVAL = count;
OUTPUT:
@@ -2765,8 +2771,8 @@ Db_create_transaction(db, prefix="/")
CODE:
/* this is *REALLY* dangerous to create a new transaction while another is open,
so use the db transaction instead. */
+ db->ts = rpmtsLink(db->ts, "URPM::DB::create_transaction");
RETVAL = db;
- ++RETVAL->count;
OUTPUT:
RETVAL
@@ -2777,10 +2783,8 @@ void
Trans_DESTROY(trans)
URPM::Transaction trans
CODE:
- if (--trans->count <= 0) {
- rpmtsFree(trans->ts);
- free(trans);
- }
+ rpmtsFree(trans->ts);
+ free(trans);
void
Trans_set_script_fd(trans, fdno)
@@ -3473,7 +3477,7 @@ Urpm_import_pubkey(...)
RETVAL = 1;
/* get transaction for importing keys, open rpmdb in write mode */
if (db) {
- ts = db->ts;
+ ts = db->ts = rpmtsLink(db->ts, "URPM::import_pubkey");
} else {
/* compabilty mode to use rpmdb installed on / */
ts = rpmtsCreate();
@@ -3619,7 +3623,7 @@ Urpm_import_pubkey(...)
}
rpmtsClean(ts);
_free(pkt);
- if (!db) rpmtsFree(ts);
+ rpmtsFree(ts);
OUTPUT:
RETVAL