diff options
Diffstat (limited to 'research')
-rw-r--r-- | research/brotli_decoder.c | 1 | ||||
-rw-r--r-- | research/draw_histogram.cc | 25 |
2 files changed, 15 insertions, 11 deletions
diff --git a/research/brotli_decoder.c b/research/brotli_decoder.c index b1d556d..4b0bc4a 100644 --- a/research/brotli_decoder.c +++ b/research/brotli_decoder.c @@ -38,6 +38,7 @@ void cleanup(Context* ctx) { void fail(Context* ctx, const char* message) { fprintf(stderr, "%s\n", message); + cleanup(ctx); exit(1); } diff --git a/research/draw_histogram.cc b/research/draw_histogram.cc index b0192a2..6ea4069 100644 --- a/research/draw_histogram.cc +++ b/research/draw_histogram.cc @@ -178,20 +178,23 @@ int main(int argc, char* argv[]) { FILE* fin = fopen(argv[1], "r"); FILE* fout = fopen(argv[2], "wb"); - uint8_t** pixel = new uint8_t*[height]; - int** histo = new int*[height]; - for (int i = 0; i < height; i++) { - pixel[i] = new uint8_t[width]; - histo[i] = new int[width]; - } + if (fin != nullptr && fout != nullptr) { + uint8_t** pixel = new uint8_t*[height]; + int** histo = new int*[height]; + for (int i = 0; i < height; i++) { + pixel[i] = new uint8_t[width]; + histo[i] = new int[width]; + } - BuildHistogram(fin, histo); - fclose(fin); + BuildHistogram(fin, histo); - ConvertToPixels(histo, pixel); + ConvertToPixels(histo, pixel); + + DrawPixels(pixel, fout); + } - DrawPixels(pixel, fout); - fclose(fout); + if (fin) fclose(fin); + if (fout) fclose(fout); return 0; } |