Skip to content

Commit

Permalink
fix some memory leaks on error paths
Browse files Browse the repository at this point in the history
  • Loading branch information
RH-steve-grubb committed Aug 16, 2022
1 parent c3ada72 commit 4839a41
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/library/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ static int write_db(const char *idx, const char *data)
{
MDB_val key, value;
MDB_txn *txn;
int rc;
int rc, ret_val = 0;
size_t len;
char *hash = NULL;

Expand All @@ -298,8 +298,10 @@ static int write_db(const char *idx, const char *data)
len = strlen(idx);
if (len > MDB_maxkeysize) {
hash = path_to_hash(idx, len);
if (hash == NULL)
if (hash == NULL) {
abort_transaction(txn);
return 5;
}
key.mv_data = (void *)hash;
key.mv_size = (SHA512_LEN * 2) + 1;
} else {
Expand All @@ -312,18 +314,21 @@ static int write_db(const char *idx, const char *data)
if ((rc = mdb_put(txn, dbi, &key, &value, 0))) {
msg(LOG_ERR, "%s", mdb_strerror(rc));
abort_transaction(txn);
return 3;
ret_val = 3;
goto out;
}

if ((rc = mdb_txn_commit(txn))) {
msg(LOG_ERR, "%s", mdb_strerror(rc));
return 4;
ret_val = 4;
goto out;
}

out:
if (len > MDB_maxkeysize)
free(hash);

return 0;
return ret_val;
}


Expand Down

0 comments on commit 4839a41

Please sign in to comment.