1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Suppress false warning for freed pointer

This commit is contained in:
Nobuyoshi Nakada 2016-06-05 20:41:32 +09:00
parent 1be2875e1d
commit 8d6e9b6658
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6

37
gc.c
View file

@ -11312,8 +11312,20 @@ objspace_malloc_gc_stress(rb_objspace_t *objspace)
} }
} }
static void static inline bool
objspace_malloc_increase(rb_objspace_t *objspace, void *mem, size_t new_size, size_t old_size, enum memop_type type) objspace_malloc_increase_report(rb_objspace_t *objspace, void *mem, size_t new_size, size_t old_size, enum memop_type type)
{
if (0) fprintf(stderr, "increase - ptr: %p, type: %s, new_size: %"PRIdSIZE", old_size: %"PRIdSIZE"\n",
mem,
type == MEMOP_TYPE_MALLOC ? "malloc" :
type == MEMOP_TYPE_FREE ? "free " :
type == MEMOP_TYPE_REALLOC ? "realloc": "error",
new_size, old_size);
return false;
}
static bool
objspace_malloc_increase_body(rb_objspace_t *objspace, void *mem, size_t new_size, size_t old_size, enum memop_type type)
{ {
if (new_size > old_size) { if (new_size > old_size) {
ATOMIC_SIZE_ADD(malloc_increase, new_size - old_size); ATOMIC_SIZE_ADD(malloc_increase, new_size - old_size);
@ -11355,13 +11367,6 @@ objspace_malloc_increase(rb_objspace_t *objspace, void *mem, size_t new_size, si
atomic_sub_nounderflow(&objspace->malloc_params.allocated_size, dec_size); atomic_sub_nounderflow(&objspace->malloc_params.allocated_size, dec_size);
} }
if (0) fprintf(stderr, "increase - ptr: %p, type: %s, new_size: %"PRIdSIZE", old_size: %"PRIdSIZE"\n",
mem,
type == MEMOP_TYPE_MALLOC ? "malloc" :
type == MEMOP_TYPE_FREE ? "free " :
type == MEMOP_TYPE_REALLOC ? "realloc": "error",
new_size, old_size);
switch (type) { switch (type) {
case MEMOP_TYPE_MALLOC: case MEMOP_TYPE_MALLOC:
ATOMIC_SIZE_INC(objspace->malloc_params.allocations); ATOMIC_SIZE_INC(objspace->malloc_params.allocations);
@ -11382,8 +11387,14 @@ objspace_malloc_increase(rb_objspace_t *objspace, void *mem, size_t new_size, si
case MEMOP_TYPE_REALLOC: /* ignore */ break; case MEMOP_TYPE_REALLOC: /* ignore */ break;
} }
#endif #endif
return true;
} }
#define objspace_malloc_increase(...) \
for (bool malloc_increase_done = objspace_malloc_increase_report(__VA_ARGS__); \
!malloc_increase_done; \
malloc_increase_done = objspace_malloc_increase_body(__VA_ARGS__))
struct malloc_obj_info { /* 4 words */ struct malloc_obj_info { /* 4 words */
size_t size; size_t size;
#if USE_GC_MALLOC_OBJ_INFO_DETAILS #if USE_GC_MALLOC_OBJ_INFO_DETAILS
@ -11695,10 +11706,10 @@ objspace_xfree(rb_objspace_t *objspace, void *ptr, size_t old_size)
#endif #endif
old_size = objspace_malloc_size(objspace, ptr, old_size); old_size = objspace_malloc_size(objspace, ptr, old_size);
free(ptr); objspace_malloc_increase(objspace, ptr, 0, old_size, MEMOP_TYPE_FREE) {
RB_DEBUG_COUNTER_INC(heap_xfree); free(ptr);
RB_DEBUG_COUNTER_INC(heap_xfree);
objspace_malloc_increase(objspace, ptr, 0, old_size, MEMOP_TYPE_FREE); }
} }
static void * static void *