diff options
author | Andrea Canciani <ranma42@gmail.com> | 2011-11-11 12:20:28 +0100 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-11-11 15:30:50 +0100 |
commit | 0e18cc6d27e59e42c6632b21c5502174c8a9eb08 (patch) | |
tree | be1aa09bca4196cdf60cf61197637ab9de51bcd9 /boilerplate/cairo-boilerplate.c | |
parent | 90b2fd34fbd8b13b0daea7780051546d1c603a33 (diff) |
boilerplate: Provide close callback after opening any2ppm output
cairo_boilerplate_open_any2ppm() returns a FILE* obtined from popen()
or fdopen(). It should hence be closed using pclose() or fclose()
respectively.
Fixes the crash on every script test on MacOS X.
Diffstat (limited to 'boilerplate/cairo-boilerplate.c')
-rw-r--r-- | boilerplate/cairo-boilerplate.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c index 91abbe219..b4b492fc1 100644 --- a/boilerplate/cairo-boilerplate.c +++ b/boilerplate/cairo-boilerplate.c @@ -789,7 +789,8 @@ any2ppm_daemon_exists (void) FILE * cairo_boilerplate_open_any2ppm (const char *filename, int page, - unsigned int flags) + unsigned int flags, + int (**close_cb) (FILE *)) { char command[4096]; #if HAS_DAEMON @@ -824,10 +825,13 @@ cairo_boilerplate_open_any2ppm (const char *filename, goto POPEN; } + *close_cb = fclose; return fdopen (sk, "r"); POPEN: #endif + + *close_cb = pclose; sprintf (command, "./any2ppm %s %d", filename, page); return popen (command, "r"); } @@ -921,10 +925,11 @@ cairo_boilerplate_convert_to_image (const char *filename, FILE *file; unsigned int flags = 0; cairo_surface_t *image; + int (*close_cb) (FILE *); int ret; RETRY: - file = cairo_boilerplate_open_any2ppm (filename, page, flags); + file = cairo_boilerplate_open_any2ppm (filename, page, flags, &close_cb); if (file == NULL) { switch (errno) { case ENOMEM: @@ -935,7 +940,7 @@ cairo_boilerplate_convert_to_image (const char *filename, } image = cairo_boilerplate_image_surface_create_from_ppm_stream (file); - ret = pclose (file); + ret = close_cb (file); /* check for fatal errors from the interpreter */ if (ret) { /* any2pmm should never die... */ cairo_surface_destroy (image); |