FIXED: Memory leaks and unused color table

This commit is contained in:
Nikola
2026-09-01 19:10:07 +03:00
parent f0207a75e8
commit a77a9c06dc
4 changed files with 15 additions and 13 deletions
+9 -6
View File
@@ -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);