commit 77e47f03220e3467c2653b25a10ba351341ad44a
parent 73efe5386024dfdebf066fef6592cc89003fda5d
Author: Frederic Cambus <fred@statdns.com>
Date: Tue, 22 Sep 2020 23:21:56 +0200
Refactor error handling in the PCBoard loader.
Diffstat:
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c
@@ -123,8 +123,7 @@ ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
ptr = realloc(pcboard_buffer, (structIndex + 1) * sizeof (struct pcbChar));
if (ptr == NULL) {
ctx->error = ANSILOVE_MEMORY_ERROR;
- free(pcboard_buffer);
- return -1;
+ goto error;
} else {
pcboard_buffer = ptr;
}
@@ -153,8 +152,7 @@ ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
if (!canvas) {
ctx->error = ANSILOVE_GD_ERROR;
- free(pcboard_buffer);
- return -1;
+ goto error;
}
/* allocate color palette */
@@ -179,12 +177,13 @@ ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
/* create output image */
- if (output(ctx, options, canvas) != 0) {
- free(pcboard_buffer);
- return -1;
- }
+ if (output(ctx, options, canvas) != 0)
+ goto error;
free(pcboard_buffer);
-
return 0;
+
+error:
+ free(pcboard_buffer);
+ return -1;
}