summaryrefslogtreecommitdiff
path: root/boilerplate
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-11-11 12:20:28 +0100
committerAndrea Canciani <ranma42@gmail.com>2011-11-11 15:30:50 +0100
commit0e18cc6d27e59e42c6632b21c5502174c8a9eb08 (patch)
treebe1aa09bca4196cdf60cf61197637ab9de51bcd9 /boilerplate
parent90b2fd34fbd8b13b0daea7780051546d1c603a33 (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')
-rw-r--r--boilerplate/cairo-boilerplate.c11
-rw-r--r--boilerplate/cairo-boilerplate.h4
2 files changed, 11 insertions, 4 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);
diff --git a/boilerplate/cairo-boilerplate.h b/boilerplate/cairo-boilerplate.h
index 061522193..b1a1f1cbd 100644
--- a/boilerplate/cairo-boilerplate.h
+++ b/boilerplate/cairo-boilerplate.h
@@ -218,7 +218,9 @@ enum {
FILE *
cairo_boilerplate_open_any2ppm (const char *filename,
int page,
- unsigned int flags);
+ unsigned int flags,
+ int (**close_cb) (FILE *));
+
cairo_surface_t *
cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file);