[gegl] tiff: Improve error handling for loader and saver
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] tiff: Improve error handling for loader and saver
- Date: Sat, 9 Jan 2016 23:47:25 +0000 (UTC)
commit 54865cb38471971217fedfc8232dfc482a0c03c7
Author: Martin Blanchard <tchaik gmx com>
Date: Mon Dec 21 23:12:08 2015 +0100
tiff: Improve error handling for loader and saver
Do not let libtiff write to stdout and correct the on-error cleanup
code (double free / unref).
https://bugzilla.gnome.org/show_bug.cgi?id=759273
operations/external/tiff-load.c | 37 +++++++++++++++++++++++++++++++++----
operations/external/tiff-save.c | 31 ++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 5 deletions(-)
---
diff --git a/operations/external/tiff-load.c b/operations/external/tiff-load.c
index aaa6c10..7d68c27 100644
--- a/operations/external/tiff-load.c
+++ b/operations/external/tiff-load.c
@@ -110,6 +110,32 @@ lseek_to_seek_type(int whence)
}
}
+static void
+error_handler(const char *module,
+ const char *format,
+ va_list arguments)
+{
+ gchar *message;
+
+ g_vasprintf(&message, format, arguments);
+ g_warning(message);
+
+ g_free(message);
+}
+
+static void
+warning_handler(const char *module,
+ const char *format,
+ va_list arguments)
+{
+ gchar *message;
+
+ g_vasprintf(&message, format, arguments);
+ g_message(message);
+
+ g_free(message);
+}
+
static tsize_t
read_from_stream(thandle_t handle,
tdata_t buffer,
@@ -707,16 +733,19 @@ prepare(GeglOperation *operation)
return;
}
+ TIFFSetErrorHandler(error_handler);
+ TIFFSetWarningHandler(warning_handler);
+
p->tiff = TIFFClientOpen("GEGL-tiff-load", "r", (thandle_t) p,
read_from_stream, write_to_stream,
seek_in_stream, close_stream,
get_file_size, NULL, NULL);
if (p->tiff == NULL)
{
- g_warning("failed to open TIFF from %s", o->path);
- g_input_stream_close(p->stream, NULL, NULL);
- if (p->file != NULL)
- g_object_unref(p->file);
+ if (o->uri != NULL && strlen(o->uri) > 0)
+ g_warning("failed to open TIFF from %s", o->uri);
+ else
+ g_warning("failed to open TIFF from %s", o->path);
cleanup(operation);
return;
}
diff --git a/operations/external/tiff-save.c b/operations/external/tiff-save.c
index e8d3a45..aadb565 100644
--- a/operations/external/tiff-save.c
+++ b/operations/external/tiff-save.c
@@ -85,6 +85,32 @@ lseek_to_seek_type(int whence)
}
}
+static void
+error_handler(const char *module,
+ const char *format,
+ va_list arguments)
+{
+ gchar *message;
+
+ g_vasprintf(&message, format, arguments);
+ g_warning(message);
+
+ g_free(message);
+}
+
+static void
+warning_handler(const char *module,
+ const char *format,
+ va_list arguments)
+{
+ gchar *message;
+
+ g_vasprintf(&message, format, arguments);
+ g_message(message);
+
+ g_free(message);
+}
+
static tsize_t
read_from_stream(thandle_t handle,
tdata_t buffer,
@@ -544,6 +570,9 @@ process(GeglOperation *operation,
goto cleanup;
}
+ TIFFSetErrorHandler(error_handler);
+ TIFFSetWarningHandler(warning_handler);
+
p->tiff = TIFFClientOpen("GEGL-tiff-save", "w", (thandle_t) p,
read_from_stream, write_to_stream,
seek_in_stream, close_stream,
@@ -551,7 +580,7 @@ process(GeglOperation *operation,
if (p->tiff == NULL)
{
status = FALSE;
- g_warning("failed to openi TIFF from %s", o->path);
+ g_warning("failed to open TIFF from %s", o->path);
goto cleanup;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]