Fixed potential memory leak from test case loading.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Fri, 29 Jul 2011 16:22:03 +0300
changeset 5791 a4e354dfcbfa
parent 5790 7a2531e260b2
child 5792 ec908de81ba5
Fixed potential memory leak from test case loading.
test/test-automation/fuzzer/fuzzer.c
test/test-automation/runner.c
--- a/test/test-automation/fuzzer/fuzzer.c	Thu Jul 28 22:19:09 2011 +0300
+++ b/test/test-automation/fuzzer/fuzzer.c	Fri Jul 29 16:22:03 2011 +0300
@@ -50,6 +50,7 @@
 
 	char *execKey = md5Context.digest;
 
+	//! \todo could this be enhanced?
 	int key = execKey[4] << 24 |
 			  execKey[9] << 16 |
 			  execKey[13] << 8 |
--- a/test/test-automation/runner.c	Thu Jul 28 22:19:09 2011 +0300
+++ b/test/test-automation/runner.c	Fri Jul 29 16:22:03 2011 +0300
@@ -264,6 +264,7 @@
 					SDL_free(reference);
 					return NULL;
 				}
+
 				SDL_snprintf(reference->directoryPath, dpSize, "%s%s.%s",
 						directoryName, name, ext);
 
@@ -398,16 +399,31 @@
 				// copy suite name
 				int length = SDL_strlen(suiteReference->name) + 1;
 				item->suiteName = SDL_malloc(length);
+				if(item->suiteName == NULL) {
+					SDL_free(item);
+					return NULL;
+				}
 				strncpy(item->suiteName, suiteReference->name, length);
 
 				// copy test name
 				length = SDL_strlen(testReference->name) + 1;
 				item->testName = SDL_malloc(length);
+				if(item->testName == NULL) {
+						SDL_free(item->suiteName);
+						SDL_free(item);
+						return NULL;
+				}
 				strncpy(item->testName, testReference->name, length);
 
 				// copy test description
 				length = SDL_strlen(testReference->description) + 1;
 				item->description = SDL_malloc(length);
+				if(item->description == NULL) {
+						SDL_free(item->description);
+						SDL_free(item->suiteName);
+						SDL_free(item);
+						return NULL;
+				}
 				strncpy(item->description, testReference->description, length);
 
 				item->requirements = testReference->requirements;