Work around issue #16. This is not very beatiful.
This commit is contained in:
		| @@ -33,6 +33,8 @@ | ||||
| #include <cairo-svg.h> | ||||
|  | ||||
| #include <gds-render/cairo-renderer/cairo-output.h> | ||||
| #include <sys/wait.h> | ||||
| #include <unistd.h> | ||||
|  | ||||
| /** | ||||
|  * @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; | ||||
| } | ||||
|  | ||||
| /** @} */ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user