From dadafa43a32942c0434d71e7e557739711e882c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 30 May 2019 14:49:35 +0200 Subject: [PATCH] Work around issue #16. This is not very beatiful. --- cairo-renderer/cairo-output.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/cairo-renderer/cairo-output.c b/cairo-renderer/cairo-output.c index 20908cc..5ee1897 100644 --- a/cairo-renderer/cairo-output.c +++ b/cairo-renderer/cairo-output.c @@ -33,6 +33,8 @@ #include #include +#include +#include /** * @brief The cairo_layer struct @@ -190,12 +192,26 @@ void cairo_render_cell_to_vector_file(struct gds_cell *cell, GList *layer_infos, int i; double rec_x0, rec_y0, rec_width, rec_height; double xmin = INT32_MAX, xmax = INT32_MIN, ymin = INT32_MAX, ymax = INT32_MIN; + pid_t process_id; if (pdf_file == NULL && svg_file == NULL) { /* No output specified */ return; } + /* Fork to a new child process. This ensures the memory leaks (see issue #16) in Cairo don't + * brick everything. + * + * And by the way: This now bricks all Windows compatibility. Deal with it. + */ + process_id = fork(); + if (process_id < 0) { + /* Well... shit... We have to run it in our process. */ + } else if (process_id > 0) { + /* Woohoo... Successfully dumped the shitty code to a unknowing victim */ + goto ret_parent; + } + layers = (struct cairo_layer *)calloc(MAX_LAYERS, sizeof(struct cairo_layer)); /* Clear layers */ @@ -310,6 +326,16 @@ ret_clear_layers: free(layers); printf("cairo export finished. It might still be buggy!\n"); + + /* If forked, suspend process */ + if (process_id == 0) + exit(0); + + /* fork didn't work. Just return here */ + return; +ret_parent: + waitpid(process_id, NULL, 0); + return; } /** @} */