From: Nick Bowler Date: Tue, 28 Jan 2014 01:03:34 +0000 (-0500) Subject: lbximg: Fix management of external palette file handles. X-Git-Url: https://git.draconx.ca/gitweb/liblbx.git/commitdiff_plain/ee019841b6c3e097f37bb739d403fe7c10d2adc6 lbximg: Fix management of external palette file handles. We leak file handles for the external and override palettes because the file is opened every time the --palette or --override options are set. Fix that up, and also close the handles when finished. --- diff --git a/src/lbximg.c b/src/lbximg.c index 2608689..dc4697b 100644 --- a/src/lbximg.c +++ b/src/lbximg.c @@ -437,6 +437,7 @@ int main(int argc, char **argv) int mode = MODE_NONE, fmt, opt, rc = EXIT_FAILURE; struct lbx_pipe_state stdin_handle = { .f = stdin }; const char *file = NULL, *fmtstring = NULL; + const char *ext_palette = NULL, *ovr_palette = NULL; FILE *palf = NULL, *overf = NULL; struct lbx_image *img; @@ -482,19 +483,11 @@ int main(int argc, char **argv) usepalette = 0; break; case 'p': - palf = fopen(optarg, "rb"); - if (!palf) { - tool_err(0, "failed to open %s", optarg); - return EXIT_FAILURE; - } + ext_palette = optarg; break; case 'O': - overf = fopen(optarg, "rb"); - if (!overf) { - tool_err(0, "failed to open %s", optarg); - return EXIT_FAILURE; - } + ovr_palette = optarg; break; case OPT_PREFIX: outname = optarg; @@ -532,6 +525,16 @@ int main(int argc, char **argv) return EXIT_FAILURE; } + if (ext_palette && !(palf = fopen(ext_palette, "rb"))) { + tool_err(0, "failed to open %s", optarg); + return EXIT_FAILURE; + } + + if (ovr_palette && !(overf = fopen(ovr_palette, "rb"))) { + tool_err(0, "failed to open %s", optarg); + return EXIT_FAILURE; + } + if (verbose || mode == MODE_IDENT) { struct lbx_imginfo info; @@ -556,5 +559,9 @@ int main(int argc, char **argv) } lbx_img_close(img); + if (palf) + fclose(palf); + if (overf) + fclose(overf); return rc; }