Commit a00e551b authored by Stephen D's avatar Stephen D
Browse files

fix memory leak

parent 74a46b11
......@@ -113,7 +113,7 @@ void hsl_to_rgb(int h, double s, double l, char *rOut, char *gOut, char *bOut)
if(h == 360) h = 0;
if(s > 1) s = 1;
if(l > 1) l = 1;
double c = (1 - abs(2 * l - 1)) * s;
double c = (1 - fabs(2 * l - 1)) * s;
double x = c * (1 - fabs(fmod(((double)h)/60, 2) - 1));
double m = l - c / 2;
double r, g, b;
......@@ -185,7 +185,7 @@ void addToImage()
p.red = nStarsAtLoc * 5;
p.green = p.red;
p.blue = p.red;
//hsl_to_rgb(nStarsAtLoc, 1, nStarsAtLoc / (double)100, &curR, &curG, &curB);
// hsl_to_rgb(nStarsAtLoc, 1, nStarsAtLoc / (double)100, &curR, &curG, &curB);
out[starX + starY * w] = p;
}
}
......@@ -234,18 +234,21 @@ void saveImage(double frame)
}
}
png_init_io (png_ptr, fp);
png_set_rows (png_ptr, info_ptr, row_pointers);
png_write_png (png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_init_io(png_ptr, fp);
png_set_rows(png_ptr, info_ptr, row_pointers);
png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
png_write_end(png_ptr, info_ptr);
fclose(fp);
//Free memory
for(int y = 0; y < h; y++)
{
png_free(png_ptr, row_pointers[y]);
}
png_free(png_ptr, row_pointers);
png_destroy_write_struct(&png_ptr, &info_ptr);
fclose(fp);
}
void saveState(int it)
......@@ -429,6 +432,10 @@ int main(int argc, char **argv)
iteration++;
}
free(out);
free(stars);
free(starsAtPixel);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment