From 1a42e75f803b917566c3403f2eb5e216fd587a10 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Mon, 18 Apr 2011 14:35:55 +0100 Subject: [PATCH] fix silly segv If you called vips_object_map() before any vips objects had been created, you got a segv. --- libvips/iofuncs/object.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libvips/iofuncs/object.c b/libvips/iofuncs/object.c index 280b06a9..c92a2b21 100644 --- a/libvips/iofuncs/object.c +++ b/libvips/iofuncs/object.c @@ -1238,11 +1238,16 @@ vips_object_map( VipsSListMap2Fn fn, void *a, void *b ) args.a = a; args.b = b; args.result = NULL; - g_mutex_lock( vips__object_all_lock ); - if( vips__object_all ) + + /* We must test vips__object_all before we lock because the lock is + * only created when the first object is created. + */ + if( vips__object_all ) { + g_mutex_lock( vips__object_all_lock ); g_hash_table_foreach( vips__object_all, (GHFunc) vips_object_map_sub, &args ); - g_mutex_unlock( vips__object_all_lock ); + g_mutex_unlock( vips__object_all_lock ); + } return( args.result ); }