]> granicus.if.org Git - gc/commitdiff
Fix test_cpp failure in case GC_DEBUG is defined
authorIvan Maidanski <ivmai@mail.ru>
Thu, 5 Jul 2018 14:38:11 +0000 (17:38 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 5 Jul 2018 14:38:11 +0000 (17:38 +0300)
Now GC_bytes_freed is updated even if the real deallocation of the
explicitly freed object is deferred.

* dbg_mlc.c (GC_debug_free): Increment GC_bytes_freed by hhdr->hb_sz
in case of GC_free is not called (when the object is filled with
GC_FREED_MEM_MARKER); add comment.

dbg_mlc.c

index 50eda33fb59f03783b9a99aee0beaaf24e1bbe37..af9652af5e0dcf8c73a9303de182a98839e78019 100644 (file)
--- a/dbg_mlc.c
+++ b/dbg_mlc.c
@@ -799,11 +799,17 @@ GC_API void GC_CALL GC_debug_free(void * p)
         GC_free(base);
       } else {
         word i;
-        word obj_sz = BYTES_TO_WORDS(hhdr->hb_sz - sizeof(oh));
+        word sz = hhdr -> hb_sz;
+        word obj_sz = BYTES_TO_WORDS(sz - sizeof(oh));
 
         for (i = 0; i < obj_sz; ++i)
           ((word *)p)[i] = GC_FREED_MEM_MARKER;
-        GC_ASSERT((word *)p + i == (word *)(base + hhdr -> hb_sz));
+        GC_ASSERT((word *)p + i == (word *)(base + sz));
+        /* Update the counter even though the real deallocation */
+        /* is deferred.                                         */
+        LOCK();
+        GC_bytes_freed += sz;
+        UNLOCK();
       }
     } /* !GC_find_leak */
 }