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.
int mode = MODE_NONE, fmt, opt, rc = EXIT_FAILURE;
struct lbx_pipe_state stdin_handle = { .f = stdin };
const char *file = NULL, *fmtstring = NULL;
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;
FILE *palf = NULL, *overf = NULL;
struct lbx_image *img;
usepalette = 0;
break;
case 'p':
usepalette = 0;
break;
case 'p':
- palf = fopen(optarg, "rb");
- if (!palf) {
- tool_err(0, "failed to open %s", optarg);
- return EXIT_FAILURE;
- }
- overf = fopen(optarg, "rb");
- if (!overf) {
- tool_err(0, "failed to open %s", optarg);
- return EXIT_FAILURE;
- }
break;
case OPT_PREFIX:
outname = optarg;
break;
case OPT_PREFIX:
outname = optarg;
+ 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;
if (verbose || mode == MODE_IDENT) {
struct lbx_imginfo info;
+ if (palf)
+ fclose(palf);
+ if (overf)
+ fclose(overf);