Skip to content

Commit 9be01bc

Browse files
committed
gc.c: also verify sized_xrealloc old size
1 parent 3c10001 commit 9be01bc

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

gc/default/default.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8270,7 +8270,7 @@ rb_gc_impl_free(void *objspace_ptr, void *ptr, size_t old_size)
82708270
struct malloc_obj_info *info = (struct malloc_obj_info *)ptr - 1;
82718271
#if VERIFY_FREE_SIZE
82728272
if (old_size && (old_size + sizeof(struct malloc_obj_info)) != info->size) {
8273-
rb_bug("buffer %p freed with size %lu, but was allocated with size %lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info));
8273+
rb_bug("buffer %p freed with old_size=%lu, but was allocated with size=%lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info));
82748274
}
82758275
#endif
82768276
ptr = info;
@@ -8379,6 +8379,11 @@ rb_gc_impl_realloc(void *objspace_ptr, void *ptr, size_t new_size, size_t old_si
83798379
struct malloc_obj_info *info = (struct malloc_obj_info *)ptr - 1;
83808380
new_size += sizeof(struct malloc_obj_info);
83818381
ptr = info;
8382+
#if VERIFY_FREE_SIZE
8383+
if (old_size && (old_size + sizeof(struct malloc_obj_info)) != info->size) {
8384+
rb_bug("buffer %p realloced with old_size=%lu, but was allocated with size=%lu", ptr, old_size, info->size - sizeof(struct malloc_obj_info));
8385+
}
8386+
#endif
83828387
old_size = info->size;
83838388
}
83848389
#endif

parse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1995,7 +1995,7 @@ parser_memhash(const void *ptr, long len)
19951995
#define STRING_TERM_LEN(str) (1)
19961996
#define STRING_TERM_FILL(str) (str->ptr[str->len] = '\0')
19971997
#define PARSER_STRING_RESIZE_CAPA_TERM(p,str,capacity,termlen) do {\
1998-
SIZED_REALLOC_N(str->ptr, char, (size_t)total + termlen, STRING_SIZE(str)); \
1998+
REALLOC_N(str->ptr, char, (size_t)total + termlen); \
19991999
str->len = total; \
20002000
} while (0)
20012001
#define STRING_SET_LEN(str, n) do { \

0 commit comments

Comments
 (0)