backends: Fix a double-free error in all backends.

Since we always call read_parse() we always free the data buffers.  Make
sure we set them to NULL or we will try to double-free them when we
terminate normally.
This commit is contained in:
Solomon Peachy 2014-01-21 20:34:00 -05:00
parent 312c210c2a
commit 4aa050f695
8 changed files with 50 additions and 22 deletions

View File

@ -411,16 +411,26 @@ static int canonselphy_read_parse(void *vctx, int data_fd)
if (!ctx)
return 1;
if (ctx->header)
if (ctx->header) {
free(ctx->header);
if (ctx->plane_y)
ctx->header = NULL;
}
if (ctx->plane_y) {
free(ctx->plane_y);
if (ctx->plane_m)
ctx->plane_y = NULL;
}
if (ctx->plane_m) {
free(ctx->plane_m);
if (ctx->plane_c)
ctx->plane_m = NULL;
}
if (ctx->plane_c) {
free(ctx->plane_c);
if (ctx->footer)
ctx->plane_c = NULL;
}
if (ctx->footer) {
free(ctx->footer);
ctx->footer = NULL;
}
/* Set up buffers */
ctx->plane_y = malloc(ctx->plane_len);
@ -656,7 +666,7 @@ top:
struct dyesub_backend canonselphy_backend = {
.name = "Canon SELPHY CP/ES",
.version = "0.65",
.version = "0.66",
.multipage_capable = 1,
.uri_prefix = "canonselphy",
.init = canonselphy_init,

View File

@ -315,8 +315,10 @@ static int dnpds40_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->databuf)
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
ctx->datalen = 0;
ctx->databuf = malloc(MAX_PRINTJOB_LEN);
@ -900,7 +902,7 @@ static int dnpds40_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
/* Exported */
struct dyesub_backend dnpds40_backend = {
.name = "DNP DS40/DS80",
.version = "0.23",
.version = "0.24",
.uri_prefix = "dnpds40",
.multipage_capable = 1,
.cmdline_usage = dnpds40_cmdline,

View File

@ -297,12 +297,18 @@ static int kodak1400_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->plane_r)
if (ctx->plane_r) {
free(ctx->plane_r);
if (ctx->plane_g)
ctx->plane_r = NULL;
}
if (ctx->plane_g) {
free(ctx->plane_g);
if (ctx->plane_b)
ctx->plane_g = NULL;
}
if (ctx->plane_b) {
free(ctx->plane_b);
ctx->plane_b = NULL;
}
/* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
@ -568,7 +574,7 @@ top:
struct dyesub_backend kodak1400_backend = {
.name = "Kodak 1400/805",
.version = "0.28",
.version = "0.29",
.uri_prefix = "kodak1400",
.multipage_capable = 1,
.cmdline_usage = kodak1400_cmdline,

View File

@ -124,8 +124,10 @@ static int kodak605_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->databuf)
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
/* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
@ -493,7 +495,7 @@ static int kodak605_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
/* Exported */
struct dyesub_backend kodak605_backend = {
.name = "Kodak 605",
.version = "0.15",
.version = "0.16",
.uri_prefix = "kodak605",
.multipage_capable = 1,
.cmdline_usage = kodak605_cmdline,

View File

@ -350,8 +350,10 @@ static int kodak6800_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->databuf)
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
/* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
@ -606,7 +608,7 @@ skip_query:
/* Exported */
struct dyesub_backend kodak6800_backend = {
.name = "Kodak 6800/6850",
.version = "0.29",
.version = "0.30",
.uri_prefix = "kodak6800",
.multipage_capable = 1,
.cmdline_usage = kodak6800_cmdline,

View File

@ -129,8 +129,10 @@ static int mitsu70x_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->databuf)
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
/* Read in initial header */
remain = sizeof(hdr);
@ -393,7 +395,7 @@ static int mitsu70x_cmdline_arg(void *vctx, int run, char *arg1, char *arg2)
/* Exported */
struct dyesub_backend mitsu70x_backend = {
.name = "Mitsubishi CP-D70/D707",
.version = "0.09",
.version = "0.10",
.uri_prefix = "mitsu70x",
.multipage_capable = 1,
.cmdline_usage = mitsu70x_cmdline,

View File

@ -1411,8 +1411,10 @@ static int shinkos2145_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->databuf)
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
/* Read in then validate header */
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
@ -1663,7 +1665,7 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end
struct dyesub_backend shinkos2145_backend = {
.name = "Shinko/Sinfonia CHC-S2145 (S2)",
.version = "0.28",
.version = "0.29",
.multipage_capable = 1,
.uri_prefix = "shinkos2145",
.cmdline_usage = shinkos2145_cmdline,

View File

@ -88,8 +88,10 @@ static int updr150_read_parse(void *vctx, int data_fd) {
if (!ctx)
return 1;
if (ctx->databuf)
if (ctx->databuf) {
free(ctx->databuf);
ctx->databuf = NULL;
}
ctx->datalen = 0;
ctx->databuf = malloc(MAX_PRINTJOB_LEN);
@ -208,7 +210,7 @@ top:
struct dyesub_backend updr150_backend = {
.name = "Sony UP-DR150",
.version = "0.10",
.version = "0.11",
.uri_prefix = "sonyupdr150",
.multipage_capable = 1,
.init = updr150_init,