diff options
author | Matt Turner <mattst88@gmail.com> | 2008-11-17 20:43:00 +0000 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2008-11-17 20:43:00 +0000 |
commit | d064ec35868720e0f29c1fe53a6e688333e71736 (patch) | |
tree | 3662aad3e5a9b536de44a3d85a8720ea06812ba9 | |
parent | 10a5d62de08035803b5fadc5fcd32c873f8b1702 (diff) |
Remove malloc return checks. Since they're in loops, they don't prevent memory from being leaked after the first iteration. Plus, when does malloc fail?
git-svn-id: svn://mattst88.com/svn/cleanbench/trunk@78 0d43b9a7-5ab2-4d7b-af9d-f64450cef757
-rw-r--r-- | assignment.c | 10 | ||||
-rw-r--r-- | bitfield.c | 19 | ||||
-rw-r--r-- | fourier.c | 19 | ||||
-rw-r--r-- | fpemulation.c | 17 | ||||
-rw-r--r-- | huffman.c | 23 | ||||
-rw-r--r-- | idea.c | 17 | ||||
-rw-r--r-- | linear.c | 31 | ||||
-rw-r--r-- | neural.c | 1 | ||||
-rw-r--r-- | numsort.c | 9 | ||||
-rw-r--r-- | stringsort.c | 14 |
10 files changed, 1 insertions, 159 deletions
diff --git a/assignment.c b/assignment.c index cf0edf7..17f8871 100644 --- a/assignment.c +++ b/assignment.c @@ -70,7 +70,6 @@ static void second_assignments(long tableau[][ASSIGNCOLS], double DoAssign(void) { - const char* context = "CPU:Assignment"; long* array = NULL; clock_t total_time = 0; int iterations = 0; @@ -89,11 +88,6 @@ DoAssign(void) ++num_arrays; array = realloc(array, sizeof(long) * ASSIGNROWS * ASSIGNCOLS * num_arrays); - if (!array) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } - /* ** Do an iteration of the assignment alg. If the ** elapsed time is less than or equal to the permitted @@ -103,10 +97,6 @@ DoAssign(void) } while (DoAssignIteration(array, num_arrays) <= MINIMUM_TICKS); } else { array = malloc(sizeof(long) * ASSIGNROWS * ASSIGNCOLS * num_arrays); - if (!array) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } } do { @@ -42,7 +42,6 @@ static void FlipBitRun(unsigned long *bitmap, double DoBitops(void) { - const char* context = "CPU:Bitfields"; unsigned long* bitarray = NULL; unsigned long* bitoparray = NULL; clock_t total_time = 0; @@ -55,20 +54,11 @@ DoBitops(void) is_adjusted = true; bitarray = realloc(bitarray, ARRAY_SIZE * sizeof(unsigned long)); - if (!bitarray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } do { bitop_array_size += 100; bitoparray = malloc(bitop_array_size * 2 * sizeof(unsigned long)); - if (!bitoparray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(bitarray); - exit(1); - } /* ** Do an iteration of the bitmap test. If the @@ -83,17 +73,8 @@ DoBitops(void) ** the array space. */ bitarray = malloc(ARRAY_SIZE * sizeof(unsigned long)); - if (!bitarray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } bitoparray = malloc(bitop_array_size * 2 * sizeof(unsigned long)); - if (!bitoparray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(bitarray); - exit(1); - } } /* @@ -43,7 +43,6 @@ static double thefunction(double x, double DoFourier(void) { - const char* context = "FPU:Transcendental"; double* abase = NULL; double* bbase = NULL; clock_t total_time = 0; @@ -58,17 +57,8 @@ DoFourier(void) array_size += 50; abase = realloc(abase, array_size * sizeof(double)); - if (!abase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } bbase = realloc(bbase, array_size * sizeof(double)); - if (!bbase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(abase); - exit(1); - } /* ** Do an iteration of the tests. If the elapsed time is @@ -82,17 +72,8 @@ DoFourier(void) ** arrays, and go. */ abase = malloc(array_size * sizeof(double)); - if (!abase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } bbase = malloc(array_size * sizeof(double)); - if (!bbase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(abase); - exit(1); - } } do { diff --git a/fpemulation.c b/fpemulation.c index 2a0d849..ac92099 100644 --- a/fpemulation.c +++ b/fpemulation.c @@ -40,7 +40,6 @@ static void SetupCPUEmFloatArrays(InternalFPF *abase, InternalFPF *bbase); double DoEmFloat(void) { - const char* context = "CPU:Floating Emulation"; InternalFPF* abase = NULL; InternalFPF* bbase = NULL; InternalFPF* cbase = NULL; @@ -50,26 +49,10 @@ DoEmFloat(void) static long loops = 1; abase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); - if (!abase) { - printf("ERROR CONDITION\nContext: %s\n", context); - exit(1); - } - bbase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); - if (!bbase) { - printf("ERROR CONDITION\nContext: %s\n", context); - free(abase); - exit(1); - } cbase = malloc(ARRAY_SIZE * sizeof(InternalFPF)); - if (!cbase) { - printf("ERROR CONDITION\nContext: %s\n", context); - free(abase); - free(bbase); - exit(1); - } SetupCPUEmFloatArrays(abase, bbase); /* FIXME: ugly */ @@ -64,7 +64,6 @@ static int GetCompBit(uint8_t *comparray, uint32_t bitoffset); double DoHuffman(void) { - const char* context = "CPU:Huffman"; char* comparray = NULL; char* decomparray = NULL; char* plaintext = NULL; @@ -85,34 +84,12 @@ DoHuffman(void) ** estimate...but, who cares?) */ plaintext = malloc(ARRAY_SIZE * sizeof(char)); - if (!plaintext) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } comparray = malloc(ARRAY_SIZE * sizeof(char)); - if (!comparray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plaintext); - exit(1); /* FIXME: do I need exits here? */ - } decomparray = malloc(ARRAY_SIZE * sizeof(char)); - if (!decomparray) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plaintext); - free(comparray); - exit(1); - } hufftree = malloc(sizeof(huff_node) * 512); - if (!hufftree) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plaintext); - free(comparray); - free(decomparray); - exit(1); - } /* ** Build the plaintext buffer. Since we want this to @@ -62,7 +62,6 @@ static void cipher_idea(uint16_t in[4], uint16_t out[4], IDEAkey Z); double DoIDEA(void) { - const char* context = "CPU:IDEA"; unsigned char* plain1 = NULL; /* First plaintext buffer */ unsigned char* crypt1 = NULL; /* Encryption buffer */ unsigned char* plain2 = NULL; /* Second plaintext buffer */ @@ -100,25 +99,11 @@ DoIDEA(void) ** Also, fill up plain1 with sample text. */ plain1 = malloc(ARRAY_SIZE); - if (!plain1) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } crypt1 = malloc(ARRAY_SIZE); - if (!crypt1) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plain1); - exit(1); - } plain2 = malloc(ARRAY_SIZE); - if (!plain2) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(plain1); - free(plain2); - exit(1); - } + /* ** Note that we build the "plaintext" by simply loading ** the array up with random numbers. @@ -65,7 +65,6 @@ static int lusolve(double a[][LUARRAYCOLS], double DoLU(void) { - const char* context = "FPU:LU"; clock_t total_time = 0; int iterations = 0; double* a = NULL; @@ -110,23 +109,8 @@ DoLU(void) ++num_arrays; abase = realloc(abase, sizeof(double) * LUARRAYCOLS * LUARRAYROWS * (num_arrays + 1)); - if (!abase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(a); - free(b); - free(LUtempvv); - exit(1); - } bbase = realloc(bbase, sizeof(double) * LUARRAYROWS * (num_arrays + 1)); - if (!bbase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(a); - free(b); - free(abase); - free(LUtempvv); - exit(1); - } } while ((DoLUIteration(a, b, abase, bbase, num_arrays) <= MINIMUM_TICKS) && (num_arrays <= ARRAY_MAX)); /* @@ -147,23 +131,8 @@ DoLU(void) ** number of arrays and proceed. */ abase = malloc(sizeof(double) * LUARRAYCOLS * LUARRAYROWS * num_arrays); - if (!abase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(a); - free(b); - free(LUtempvv); - exit(1); - } bbase = malloc(sizeof(double) * LUARRAYROWS * num_arrays); - if (!bbase) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - free(a); - free(b); - free(abase); - free(LUtempvv); - exit(1); - } } do { @@ -116,7 +116,6 @@ static int read_data_file(); double DoNNET(void) { -/* const char* context="CPU:NNET"; */ /* Since we never fprintf errors here, we don't need this */ clock_t total_time = 0; int iterations = 0; static bool is_adjusted = false; @@ -38,7 +38,6 @@ static void NumSift(long *array, unsigned long min, unsigned long max); double DoNumSort (void) { - const char* context = "CPU:Numeric Sort"; long* array = NULL; clock_t total_time = 0; int iterations = 0; @@ -58,10 +57,6 @@ DoNumSort (void) ++num_arrays; array = realloc(array, num_arrays * ARRAY_SIZE * sizeof(long)); - if (!array) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } /* ** Do an iteration of the numeric sort. If the @@ -72,10 +67,6 @@ DoNumSort (void) } while (DoNumSortIteration(array, num_arrays) <= MINIMUM_TICKS); } else { array = malloc(num_arrays * ARRAY_SIZE * sizeof(long)); - if (!array) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } } /* diff --git a/stringsort.c b/stringsort.c index ed8c913..b38f5bd 100644 --- a/stringsort.c +++ b/stringsort.c @@ -52,7 +52,6 @@ static void strsift(unsigned long *optrarray, double DoStringSort(void) { - const char* context = "CPU:String Sort"; unsigned char* array = NULL; clock_t total_time = 0; int iterations = 0; @@ -72,10 +71,6 @@ DoStringSort(void) ** (this can happen during string adjustment) */ array = realloc(array, (ARRAY_SIZE + 100) * num_arrays); - if (!array) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } /* ** Do an iteration of the string sort. If the @@ -90,10 +85,6 @@ DoStringSort(void) ** Simply allocate the space for the array. */ array = malloc((ARRAY_SIZE + 100) * num_arrays); - if (!array) { - fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context); - exit(1); - } } do { @@ -247,11 +238,6 @@ while(k<num_arrays) ** offset pointer array. */ optrarray = malloc(*nstrings * sizeof(unsigned long) * num_arrays); -if (!optrarray) { - /* FIXME: add error message */ - free(strarray); - exit(1); -} /* ** Go through the newly-built string array, building |