mdbx: tools/tests - fix minor memleaks (for CI with Valgrind).

Change-Id: I0e2217d568259f26cd7c4da800a13577962742f7
This commit is contained in:
Leo Yuriev 2015-11-19 14:01:31 +03:00
parent 0230e4fda2
commit f3043badc5
2 changed files with 25 additions and 8 deletions

View File

@ -122,27 +122,42 @@ error(const char* msg, ...) {
} }
} }
static void pagemap_cleanup(void) {
int i;
for( i = 1; i < MAX_DBI; ++i ) {
if (walk.dbi_names[i]) {
free((void *) walk.dbi_names[i]);
walk.dbi_names[i] = NULL;
}
}
free(walk.pagemap);
walk.pagemap = NULL;
}
static int pagemap_lookup_dbi(const char* dbi) { static int pagemap_lookup_dbi(const char* dbi) {
static int last; static int last;
int i;
if (last > 0 && strcmp(walk.dbi_names[last], dbi) == 0) if (last > 0 && strcmp(walk.dbi_names[last], dbi) == 0)
return last; return last;
for(last = 1; walk.dbi_names[last] && last < MAX_DBI; ++last) for(i = 1; walk.dbi_names[i] && last < MAX_DBI; ++i)
if (strcmp(walk.dbi_names[last], dbi) == 0) if (strcmp(walk.dbi_names[i], dbi) == 0)
return last; return last = i;
if (last == MAX_DBI) if (i == MAX_DBI)
return last = -1; return -1;
walk.dbi_names[last] = strdup(dbi); walk.dbi_names[i] = strdup(dbi);
if (verbose > 1) { if (verbose > 1) {
print(" - found '%s' area\n", dbi); print(" - found '%s' area\n", dbi);
fflush(NULL); fflush(NULL);
} }
return last; return last = i;
} }
static void problem_add(const char* object, size_t entry_number, const char* msg, const char *extra, ...) { static void problem_add(const char* object, size_t entry_number, const char* msg, const char *extra, ...) {
@ -581,6 +596,8 @@ int main(int argc, char *argv[])
struct timespec timestamp_start, timestamp_finish; struct timespec timestamp_start, timestamp_finish;
double elapsed; double elapsed;
atexit(pagemap_cleanup);
if (clock_gettime(CLOCK_MONOTONIC, &timestamp_start)) { if (clock_gettime(CLOCK_MONOTONIC, &timestamp_start)) {
rc = errno; rc = errno;
error("clock_gettime failed, error %d %s\n", rc, mdbx_strerror(rc)); error("clock_gettime failed, error %d %s\n", rc, mdbx_strerror(rc));
@ -897,7 +914,6 @@ bailout:
mdbx_txn_abort(locktxn); mdbx_txn_abort(locktxn);
if (env) if (env)
mdbx_env_close(env); mdbx_env_close(env);
free(walk.pagemap);
fflush(NULL); fflush(NULL);
if (rc) { if (rc) {
if (rc < 0) if (rc < 0)

View File

@ -159,6 +159,7 @@ int main(int argc,char * argv[])
mdb_dbi_close(env, dbi); mdb_dbi_close(env, dbi);
#endif #endif
mdb_env_close(env); mdb_env_close(env);
free(sval);
return 0; return 0;
} }