mirror of
				https://github.com/isar/libmdbx.git
				synced 2025-10-31 03:29:01 +08:00 
			
		
		
		
	mdbx: tools/tests - fix minor memleaks (for CI with Valgrind).
Change-Id: I0e2217d568259f26cd7c4da800a13577962742f7
This commit is contained in:
		
							
								
								
									
										32
									
								
								mdb_chk.c
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								mdb_chk.c
									
									
									
									
									
								
							| @@ -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, ×tamp_start)) { | 	if (clock_gettime(CLOCK_MONOTONIC, ×tamp_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) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user