From efdf33f3dea462388ed3423cd9282a794b648b8a Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 12 Sep 2019 09:49:49 +0100 Subject: [PATCH] add vips_error_buffer_copy() Add vips_error_buffer_copy() to fix a race in error buffer fetch. See https://github.com/libvips/libvips/issues/1423 Thanks @dineshkannaa --- ChangeLog | 1 + libvips/include/vips/error.h | 1 + libvips/iofuncs/error.c | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index 7e0fd951..634d4f8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ - handle alpha in heifload / heifsave [meyermarcel] - add @interpretation and @format to rawload - nifti load/save uses double for all floating point metadata +- add vips_error_buffer_copy() 31/8/19 started 8.8.3 - revert sharpen restoring the input colourspace diff --git a/libvips/include/vips/error.h b/libvips/include/vips/error.h index 1b697afa..4e04da08 100644 --- a/libvips/include/vips/error.h +++ b/libvips/include/vips/error.h @@ -36,6 +36,7 @@ extern "C" { #endif /*__cplusplus*/ const char *vips_error_buffer( void ); +char *vips_error_buffer_copy( void ); void vips_error_clear( void ); void vips_error_freeze( void ); diff --git a/libvips/iofuncs/error.c b/libvips/iofuncs/error.c index 8f12013e..16562384 100644 --- a/libvips/iofuncs/error.c +++ b/libvips/iofuncs/error.c @@ -14,6 +14,8 @@ * - gtkdoc comments * 24/6/10 * - fmt to error_exit() may be NULL + * 12/9/19 [dineshkannaa] + * - add vips_error_buffer_copy() */ /* @@ -184,6 +186,26 @@ vips_error_buffer( void ) return( msg ); } +/** + * vips_error_buffer_copy: + * + * Return a copy of the vips error buffer, and clear it. + * + * Returns: a copy of the libvips error buffer + */ +char * +vips_error_buffer_copy( void ) +{ + char *msg; + + g_mutex_lock( vips__global_lock ); + msg = g_strdup( vips_buf_all( &vips_error_buf ) ); + vips_error_clear(); + g_mutex_unlock( vips__global_lock ); + + return( msg ); +} + /* Some systems do not have va_copy() ... this might work (it does on MSVC), * apparently. *