From 01a9947006753d6bd4674483c619c7d2ae79bfbc Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 17 Feb 2022 14:30:02 +0000 Subject: [PATCH] remove atexit use too unreliable to be useful --- configure.ac | 2 +- libvips/iofuncs/init.c | 45 +++++++++++++++--------------------------- meson.build | 2 +- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/configure.ac b/configure.ac index 5d260a4d..ed9326b9 100644 --- a/configure.ac +++ b/configure.ac @@ -392,7 +392,7 @@ fi AC_FUNC_MEMCMP AC_FUNC_MMAP AC_FUNC_VPRINTF -AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasecmp strchr strcspn strdup strerror strrchr strspn vsnprintf realpath mkstemp mktemp random rand sysconf atexit _aligned_malloc posix_memalign memalign]) +AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasecmp strchr strcspn strdup strerror strrchr strspn vsnprintf realpath mkstemp mktemp random rand sysconf _aligned_malloc posix_memalign memalign]) AC_CHECK_LIB(m,cbrt,[AC_DEFINE(HAVE_CBRT,1,[have cbrt() in libm.])]) AC_CHECK_LIB(m,hypot,[AC_DEFINE(HAVE_HYPOT,1,[have hypot() in libm.])]) AC_CHECK_LIB(m,atan2,[AC_DEFINE(HAVE_ATAN2,1,[have atan2() in libm.])]) diff --git a/libvips/iofuncs/init.c b/libvips/iofuncs/init.c index 43c0de87..68e34839 100644 --- a/libvips/iofuncs/init.c +++ b/libvips/iofuncs/init.c @@ -418,30 +418,6 @@ vips_leak( void ) return( n_leaks ); } -/* This is not guaranteed to be called, and might be called after many parts - * of libvips have been freed. Threads can be in an indeterminate state. - * You must be very careful to avoid segvs. - */ -static void -vips__atexit( void ) -{ - /* In dev releases, always show leaks. But not more than once, it's - * annoying. - */ -#ifndef DEBUG_LEAK - if( vips__leak ) -#endif /*DEBUG_LEAK*/ - { - static gboolean done = FALSE; - - if( !done ) { - done = TRUE; - vips_cache_drop_all(); - vips_leak(); - } - } -} - /** * vips_init: * @argv0: name of application @@ -658,10 +634,6 @@ vips_init( const char *argv0 ) gsf_init(); #endif /*HAVE_GSF*/ -#ifdef HAVE_ATEXIT - atexit( vips__atexit ); -#endif /*HAVE_ATEXIT*/ - #ifdef DEBUG_LEAK vips__image_pixels_quark = g_quark_from_static_string( "vips-image-pixels" ); @@ -750,11 +722,26 @@ void vips_shutdown( void ) { #ifdef DEBUG - printf( "vips_shutdown:\n" ); #endif /*DEBUG*/ + printf( "vips_shutdown:\n" ); vips_cache_drop_all(); + /* In dev releases, always show leaks. But not more than once, it's + * annoying. + */ +#ifndef DEBUG_LEAK + if( vips__leak ) +#endif /*DEBUG_LEAK*/ + { + static gboolean done = FALSE; + + if( !done ) { + done = TRUE; + vips_leak(); + } + } + #if ENABLE_DEPRECATED im_close_plugins(); #endif diff --git a/meson.build b/meson.build index 449e83c2..8aa35b9e 100644 --- a/meson.build +++ b/meson.build @@ -107,7 +107,7 @@ if cpp.compiles(vector_arithmetic_check, name: 'Has vector arithmetic', dependen endif endif -func_names = [ 'getcwd', 'gettimeofday', 'getwd', 'memset', 'munmap', 'putenv', 'realpath', 'strcasecmp', 'strchr', 'strcspn', 'strdup', 'strerror', 'strrchr', 'strspn', 'vsnprintf', 'realpath', 'mkstemp', 'mktemp', 'random', 'rand', 'sysconf', 'atexit', '_aligned_malloc', 'posix_memalign', 'memalign', 'cbrt', 'hypot', 'atan2', 'asinh' ] +func_names = [ 'getcwd', 'gettimeofday', 'getwd', 'memset', 'munmap', 'putenv', 'realpath', 'strcasecmp', 'strchr', 'strcspn', 'strdup', 'strerror', 'strrchr', 'strspn', 'vsnprintf', 'realpath', 'mkstemp', 'mktemp', 'random', 'rand', 'sysconf', '_aligned_malloc', 'posix_memalign', 'memalign', 'cbrt', 'hypot', 'atan2', 'asinh' ] foreach func_name : func_names if cc.has_function(func_name, dependencies: m_dep) cfg_var.set('HAVE_' + func_name.to_upper(), '1')