[前][次][番号順一覧][スレッド一覧]

ruby-changes:69381

From: Nobuyoshi <ko1@a...>
Date: Sun, 24 Oct 2021 16:24:23 +0900 (JST)
Subject: [ruby-changes:69381] 8d6e9b6658 (master): Suppress false warning for freed pointer

https://git.ruby-lang.org/ruby.git/commit/?id=8d6e9b6658

From 8d6e9b66580278900020abf77dc1aa6427a060f9 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 5 Jun 2016 20:41:32 +0900
Subject: Suppress false warning for freed pointer

---
 gc.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/gc.c b/gc.c
index 84df8a79eb..11d7bd91f6 100644
--- a/gc.c
+++ b/gc.c
@@ -11312,8 +11312,20 @@ objspace_malloc_gc_stress(rb_objspace_t *objspace) https://github.com/ruby/ruby/blob/trunk/gc.c#L11312
     }
 }
 
-static void
-objspace_malloc_increase(rb_objspace_t *objspace, void *mem, size_t new_size, size_t old_size, enum memop_type type)
+static inline bool
+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) {
 	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 https://github.com/ruby/ruby/blob/trunk/gc.c#L11367
 	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) {
       case MEMOP_TYPE_MALLOC:
 	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 https://github.com/ruby/ruby/blob/trunk/gc.c#L11387
       case MEMOP_TYPE_REALLOC: /* ignore */ break;
     }
 #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 */
     size_t size;
 #if USE_GC_MALLOC_OBJ_INFO_DETAILS
@@ -11695,10 +11706,10 @@ objspace_xfree(rb_objspace_t *objspace, void *ptr, size_t old_size) https://github.com/ruby/ruby/blob/trunk/gc.c#L11706
 #endif
     old_size = objspace_malloc_size(objspace, ptr, old_size);
 
-    free(ptr);
-    RB_DEBUG_COUNTER_INC(heap_xfree);
-
-    objspace_malloc_increase(objspace, ptr, 0, old_size, MEMOP_TYPE_FREE);
+    objspace_malloc_increase(objspace, ptr, 0, old_size, MEMOP_TYPE_FREE) {
+	free(ptr);
+	RB_DEBUG_COUNTER_INC(heap_xfree);
+    }
 }
 
 static void *
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]