mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +01:00 
			
		
		
		
	gtype: Use g_malloc0 and g_free_sized to allocate and free memory
We've a sized free now, so we can just use it!
This commit is contained in:
		| @@ -1954,7 +1954,7 @@ g_type_create_instance (GType type) | ||||
|       private_size += ALIGN_STRUCT (1); | ||||
|  | ||||
|       /* Allocate one extra pointer size... */ | ||||
|       allocated = g_slice_alloc0 (private_size + ivar_size + sizeof (gpointer)); | ||||
|       allocated = g_malloc0 (private_size + ivar_size + sizeof (gpointer)); | ||||
|       /* ... and point it back to the start of the private data. */ | ||||
|       *(gpointer *) (allocated + private_size + ivar_size) = allocated + ALIGN_STRUCT (1); | ||||
|  | ||||
| @@ -1964,7 +1964,7 @@ g_type_create_instance (GType type) | ||||
|     } | ||||
|   else | ||||
| #endif | ||||
|     allocated = g_slice_alloc0 (private_size + ivar_size); | ||||
|     allocated = g_malloc0 (private_size + ivar_size); | ||||
|  | ||||
|   instance = (GTypeInstance *) (allocated + private_size); | ||||
|  | ||||
| @@ -2054,14 +2054,14 @@ g_type_free_instance (GTypeInstance *instance) | ||||
|       /* Clear out the extra pointer... */ | ||||
|       *(gpointer *) (allocated + private_size + ivar_size) = NULL; | ||||
|       /* ... and ensure we include it in the size we free. */ | ||||
|       g_slice_free1 (private_size + ivar_size + sizeof (gpointer), allocated); | ||||
|       g_free_sized (allocated, private_size + ivar_size + sizeof (gpointer)); | ||||
|  | ||||
|       VALGRIND_FREELIKE_BLOCK (allocated + ALIGN_STRUCT (1), 0); | ||||
|       VALGRIND_FREELIKE_BLOCK (instance, 0); | ||||
|     } | ||||
|   else | ||||
| #endif | ||||
|     g_slice_free1 (private_size + ivar_size, allocated); | ||||
|     g_free_sized (allocated, private_size + ivar_size); | ||||
|  | ||||
| #ifdef	G_ENABLE_DEBUG | ||||
|   IF_DEBUG (INSTANCE_COUNT) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user