safer vips_operation_new()

fixes "$ vips vips" segv
This commit is contained in:
John Cupitt 2014-05-06 18:49:20 +01:00
parent 44f8b0d8ac
commit c8d6aac98d
2 changed files with 17 additions and 2 deletions

View File

@ -2548,6 +2548,7 @@ vips_type_find( const char *basename, const char *nickname )
{
static GOnce once = G_ONCE_INIT;
GType base;
GType type;
vips__object_nickname_table = (GHashTable *) g_once( &once,
@ -2555,8 +2556,15 @@ vips_type_find( const char *basename, const char *nickname )
type = GPOINTER_TO_INT( g_hash_table_lookup(
vips__object_nickname_table, (void *) nickname ) );
/* We must only search below basename ... check that the cache hit is
* in the right part of the tree.
*/
if( !(base = g_type_from_name( basename )) )
return( 0 );
if( !type ||
type == -1 ) {
type == -1 ||
!g_type_is_a( type, base ) ) {
VipsObjectClass *class;
if( !(class = vips_class_find( basename, nickname )) )

View File

@ -423,6 +423,7 @@ VipsOperation *
vips_operation_new( const char *name )
{
GType type;
VipsObject *object;
VipsOperation *operation;
vips_check_init();
@ -433,7 +434,13 @@ vips_operation_new( const char *name )
return( NULL );
}
operation = VIPS_OPERATION( g_object_new( type, NULL ) );
if( !(object = g_object_new( type, NULL )) ) {
vips_error( "VipsOperation",
_( "\"%s\" is not an instantiable class" ), name );
return( NULL );
}
operation = VIPS_OPERATION( object );
VIPS_DEBUG_MSG( "vips_operation_new: %s (%p)\n", name, operation );