oops memory problems

removed unnecessary and broken im_malloc() compat functions, fixed a
memleak
This commit is contained in:
John Cupitt 2011-09-23 12:27:37 +01:00
parent ea84ce8ed0
commit 2959dbff39
6 changed files with 8 additions and 61 deletions

3
TODO
View File

@ -5,9 +5,6 @@
#endif /*WITH_DMALLOC*/
- (header -f height file.v) seems to segv?
- do clip/embed etc. in new style, good to get everything that VipsAdd uses in
the new stack

View File

@ -853,53 +853,3 @@ vips__init_wrap7_classes( void )
(void) im_map_packages( (VSListMap2Fn) vips_wrap7_build_package, NULL );
}
/* The vips7 malloc/free need to be thin wrappers over g_malloc()/g_free(),
* since we pass strings to and from the library and need to be able to free
* with either.
*/
int
im_free( void *s )
{
g_free( s );
return( 0 );
}
void *
im_malloc( IMAGE *im, size_t size )
{
void *buf;
if( !(buf = g_try_malloc( size )) ) {
im_error( "im_malloc",
_( "out of memory --- size == %dMB" ),
(int) (size / (1024.0*1024.0)) );
im_warn( "im_malloc",
_( "out of memory --- size == %dMB" ),
(int) (size / (1024.0*1024.0)) );
return( NULL );
}
if( im && im_add_close_callback( im,
(im_callback_fn) im_free, buf, NULL ) ) {
im_free( buf );
return( NULL );
}
return( buf );
}
char *
im_strdup( IMAGE *im, const char *str )
{
int l = strlen( str );
char *buf;
if( !(buf = (char *) im_malloc( im, l + 1 )) )
return( NULL );
strcpy( buf, str );
return( buf );
}

View File

@ -65,7 +65,7 @@ G_STMT_START { \
((T *) vips_malloc( VIPS_OBJECT( OBJ ), (N) * sizeof( T )))
void *vips_malloc( VipsObject *object, size_t size );
char *vips_strdup( VipsObject *object, char *str );
char *vips_strdup( VipsObject *object, const char *str );
int vips_free( void *buf );
void vips_tracked_free( void *s );

View File

@ -285,12 +285,6 @@ int im_generate( VipsImage *im,
#define im__print_renders vips__print_renders
#define im_cache vips_image_cache
/* vips_alloc() and friends are not the same, we need to keep these as C.
*/
char *im_strdup( IMAGE *im, const char *str );
int im_free( void *s );
void *im_malloc( IMAGE *im, size_t size );
#define IM_FREEF( F, S ) \
G_STMT_START { \
if( S ) { \
@ -323,6 +317,11 @@ G_STMT_START { \
} \
} G_STMT_END
#define im_malloc( IM, SZ ) \
(vips_malloc( VIPS_OBJECT( IM ), (SZ) ))
#define im_free vips_free
#define im_strdup( IM, STR ) \
(vips_strdup( VIPS_OBJECT( IM ), (STR) ))
#define IM_NEW( IM, T ) ((T *) im_malloc( (IM), sizeof( T )))
#define IM_ARRAY( IM, N, T ) ((T *) im_malloc( (IM), (N) * sizeof( T )))

View File

@ -491,6 +491,7 @@ lazy_free_cb( VipsImage *image, Lazy *lazy )
g_free( lazy->filename );
VIPS_UNREF( lazy->real );
g_free( lazy );
}
static Lazy *

View File

@ -171,7 +171,7 @@ vips_malloc( VipsObject *object, size_t size )
* Returns: a pointer to the allocated memory
*/
char *
vips_strdup( VipsObject *object, char *str )
vips_strdup( VipsObject *object, const char *str )
{
char *str_dup;