FIXED: Memory leaks and unused color table
This commit is contained in:
@@ -233,14 +233,16 @@ int main(int argc, char** argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
output_data = malloc(strlen(optarg) + 1);
|
||||
int output_data_length = strlen(optarg) + 1;
|
||||
output_data = malloc(output_data_length);
|
||||
if (output_data == NULL)
|
||||
{
|
||||
fprintf(stderr,"Memory allocation failed.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
strcpy(output_data,optarg);
|
||||
strncpy(output_data,optarg,output_data_length);
|
||||
output_data[output_data_length-1] = 0;
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
@@ -269,14 +271,15 @@ int main(int argc, char** argv)
|
||||
float complex start = (starting_point_real + starting_point_imaginary*I);
|
||||
int bytesPerColour = colored ? 3 : 1;
|
||||
ssize_t absolute_height = height >= 0 ? height : height * - 1;
|
||||
|
||||
if (will_test)
|
||||
return tests() ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
||||
unsigned char *imageArr = malloc(width*absolute_height*bytesPerColour);// allocate image array on the heap to support large images as the stack is usually only 8 MB big
|
||||
|
||||
if(imageArr == NULL)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (will_test)
|
||||
return tests() ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
||||
|
||||
if (!(nGiven && rGiven && oGiven && dGiven && sGiven))
|
||||
{
|
||||
checkInputs(nGiven,rGiven,oGiven,dGiven,sGiven);
|
||||
|
||||
@@ -120,9 +120,9 @@ void tricorn(float complex start, size_t width, ssize_t height, float res, unsig
|
||||
img[position] = value;
|
||||
}
|
||||
else {
|
||||
img[position] = ((value*3) % 255);
|
||||
img[position + 1] = ((value*2) % 255);
|
||||
img[position + 2] = ((value*5) % 255);
|
||||
img[position] = color_lookup_table[value][0];
|
||||
img[position + 1] = color_lookup_table[value][1];
|
||||
img[position + 2] = color_lookup_table[value][2];
|
||||
}
|
||||
}
|
||||
// Accumulate the imaginary part
|
||||
|
||||
@@ -120,9 +120,9 @@ void tricorn_V2(float complex start, size_t width, ssize_t height, float res, un
|
||||
img[position] = value;
|
||||
}
|
||||
else {
|
||||
img[position] = ((value*3) % 255);
|
||||
img[position + 1] = ((value*2) % 255);
|
||||
img[position + 2] = ((value*5) % 255);
|
||||
img[position] = color_lookup_table[value][0];
|
||||
img[position + 1] = color_lookup_table[value][1];
|
||||
img[position + 2] = color_lookup_table[value][2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,6 @@ void tricorn_V3(float complex start, size_t width, ssize_t height, float res, un
|
||||
args->consts = consts;
|
||||
if(pthread_create(&threads[i],NULL,compute,args)){
|
||||
compute(args);
|
||||
free(args);
|
||||
args = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user