Skip to content

Commit 5d5d8ab

Browse files
authored
Merge pull request #5715 from larsewi/cf-check
CFE-4508: Fixed valgrind errors in cf-check
2 parents 0887b41 + d963316 commit 5d5d8ab

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

cf-check/diagnose.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ size_t diagnose_files(
615615

616616
if (symlink_target != NULL)
617617
{
618-
int usage;
618+
int usage = 0;
619619
bool needs_rotation = lmdb_file_needs_rotation(symlink_target, &usage);
620620
Log(LOG_LEVEL_INFO,
621621
"Status of '%s' -> '%s': %s [%d%% usage%s]\n",
@@ -627,7 +627,7 @@ size_t diagnose_files(
627627
}
628628
else
629629
{
630-
int usage;
630+
int usage = 0;
631631
bool needs_rotation = lmdb_file_needs_rotation(filename, &usage);
632632
Log(LOG_LEVEL_INFO,
633633
"Status of '%s': %s [%d%% usage%s]\n",

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);

tests/valgrind-check/valgrind.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function check_valgrind_output {
3737
fi
3838
echo "Looking for problems in $1:"
3939
grep -i "ERROR SUMMARY: 0 errors" "$1"
40-
cat $1 | sed -e "/ 0 errors/d" -e "/and suppressed error/d" -e "/a memory error detector/d" -e "/This database contains unknown binary data/d" > filtered.txt
40+
cat $1 | sed -e "/ 0 errors/d" -e "/and suppressed error/d" -e "/a memory error detector/d" -e "/This database contains unknown binary data/d" -e "/error: Problems detected in 1\/1 databases/d" -e "/error: Failed to stat() 'no-such-file.lmdb'/d" -e "/Status of 'no-such-file.lmdb': SYSTEM_ERROR 2/d" > filtered.txt
4141
no_errors filtered.txt
4242
set +e
4343
grep -i "at 0x" filtered.txt
@@ -98,6 +98,10 @@ echo "Running cf-check diagnose --validate on all databases:"
9898
valgrind $VG_OPTS /var/cfengine/bin/cf-check diagnose --validate 2>&1 | tee cf_check_validate_all_1.txt
9999
check_valgrind_output cf_check_validate_all_1.txt
100100

101+
echo "Running cf-check diagnose --validate on non-existent file:"
102+
valgrind $VG_OPTS /var/cfengine/bin/cf-check diagnose --validate no-such-file.lmdb 2>&1 | tee cf_check_validate_non_existent.txt
103+
check_valgrind_output cf_check_validate_non_existent.txt
104+
101105
check_masterfiles_and_inputs
102106

103107
print_ps

0 commit comments

Comments
 (0)