Skip to content

Commit e55124b

Browse files
committed
Fixed memory leak when running cf-check on non-existent file
Ticket: CFE-4508 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent e7ea45f commit e55124b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

cf-check/validate.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,27 +592,34 @@ int CFCheck_Validate(const char *path)
592592
rc = mdb_env_open(env, path, MDB_NOSUBDIR | MDB_RDONLY, 0644);
593593
if (rc != 0)
594594
{
595+
mdb_env_close(env);
595596
return rc;
596597
}
597598

598599
MDB_txn *txn;
599600
rc = mdb_txn_begin(env, NULL, MDB_RDONLY, &txn);
600601
if (rc != 0)
601602
{
603+
mdb_env_close(env);
602604
return rc;
603605
}
604606

605607
MDB_dbi dbi;
606608
rc = mdb_open(txn, NULL, 0, &dbi);
607609
if (rc != 0)
608610
{
611+
mdb_txn_abort(txn);
612+
mdb_env_close(env);
609613
return rc;
610614
}
611615

612616
MDB_cursor *cursor;
613617
rc = mdb_cursor_open(txn, dbi, &cursor);
614618
if (rc != 0)
615619
{
620+
mdb_close(env, dbi);
621+
mdb_txn_abort(txn);
622+
mdb_env_close(env);
616623
return rc;
617624
}
618625

@@ -627,6 +634,10 @@ int CFCheck_Validate(const char *path)
627634
{
628635
// At this point, not found is expected, anything else is an error
629636
DestroyValidator(&state);
637+
mdb_cursor_close(cursor);
638+
mdb_close(env, dbi);
639+
mdb_txn_abort(txn);
640+
mdb_env_close(env);
630641
return rc;
631642
}
632643
mdb_cursor_close(cursor);

0 commit comments

Comments
 (0)