Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ecf3285

Browse files
jcupittkleisauke
authored andcommitted
avoid a critical during module load (libvips#3391)
If load fails, don't call `make_resident`, since this will trigger a glib critical error. See libvips/ruby-vips#364 (comment) (cherry picked from commit 8390e88)
1 parent 2e6ac93 commit ecf3285

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

libvips/iofuncs/init.c

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -254,34 +254,32 @@ vips_get_prgname( void )
254254

255255
#ifdef ENABLE_MODULES
256256
/* Load all plugins in a directory ... look for '.<G_MODULE_SUFFIX>' or
257-
* '.plg' (deprecated) suffix. Error if we had any probs.
257+
* '.plg' (deprecated) suffix.
258258
*/
259-
static int
259+
static void
260260
vips_load_plugins( const char *fmt, ... )
261261
{
262262
va_list ap;
263263
char dir_name[VIPS_PATH_MAX];
264264
GDir *dir;
265265
const char *name;
266-
int result;
267266

268-
/* Silently succeed if we can't do modules.
267+
/* Do nothing if modules aren't supported.
269268
*/
270269
if( !g_module_supported() )
271-
return( 0 );
270+
return;
272271

273272
va_start( ap, fmt );
274273
(void) vips_vsnprintf( dir_name, VIPS_PATH_MAX - 1, fmt, ap );
275274
va_end( ap );
276275

277276
g_info( "searching \"%s\"", dir_name );
278277

279-
if( !(dir = g_dir_open( dir_name, 0, NULL )) )
280-
/* Silent success for dir not there.
281-
*/
282-
return( 0 );
278+
/* Do nothing if directory is not present.
279+
*/
280+
if( !(dir = g_dir_open( dir_name, 0, NULL )) )
281+
return;
283282

284-
result = 0;
285283
while( (name = g_dir_read_name( dir )) )
286284
if( vips_ispostfix( name, "." G_MODULE_SUFFIX )
287285
#if ENABLE_DEPRECATED
@@ -297,20 +295,17 @@ vips_load_plugins( const char *fmt, ... )
297295
g_info( "loading \"%s\"", path );
298296

299297
module = g_module_open( path, G_MODULE_BIND_LAZY );
300-
if( !module ) {
298+
if( module )
299+
/* Modules will almost certainly create new
300+
* types, so they can't be unloaded.
301+
*/
302+
g_module_make_resident( module );
303+
else
301304
g_warning( _( "unable to load \"%s\" -- %s" ),
302305
path, g_module_error() );
303-
result = -1;
304-
}
305306

306-
/* Modules will almost certainly create new types, so
307-
* they can't be unloaded.
308-
*/
309-
g_module_make_resident( module );
310307
}
311308
g_dir_close( dir );
312-
313-
return( result );
314309
}
315310
#endif /*ENABLE_MODULES*/
316311

@@ -611,13 +606,13 @@ vips_init( const char *argv0 )
611606
* modules, or we might try loading an operation into a library that
612607
* already has that operation built in.
613608
*/
614-
(void) vips_load_plugins( "%s/vips-modules-%d.%d",
609+
vips_load_plugins( "%s/vips-modules-%d.%d",
615610
libdir, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION );
616611

617612
#if ENABLE_DEPRECATED
618613
/* Load any vips8 plugins from the vips libdir.
619614
*/
620-
(void) vips_load_plugins( "%s/vips-plugins-%d.%d",
615+
vips_load_plugins( "%s/vips-plugins-%d.%d",
621616
libdir, VIPS_MAJOR_VERSION, VIPS_MINOR_VERSION );
622617

623618
/* Load up any vips7 plugins in the vips libdir. We don't error on

0 commit comments

Comments
 (0)