File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,7 +58,11 @@ void msgpack_buffer_init(msgpack_buffer_t* b)
5858static void _msgpack_buffer_chunk_destroy (msgpack_buffer_chunk_t * c )
5959{
6060 if (c -> mem != NULL ) {
61- if (!msgpack_rmem_free (& s_rmem , c -> mem )) {
61+ if (c -> rmem ) {
62+ if (!msgpack_rmem_free (& s_rmem , c -> mem )) {
63+ rb_bug ("Failed to free an rmem pointer, memory leak?" );
64+ }
65+ } else {
6266 xfree (c -> mem );
6367 }
6468 /* no needs to update rmem_owner because chunks will not be
@@ -341,6 +345,8 @@ static inline void* _msgpack_buffer_chunk_malloc(
341345 size_t required_size , size_t * allocated_size )
342346{
343347 if (required_size <= MSGPACK_RMEM_PAGE_SIZE ) {
348+ c -> rmem = true;
349+
344350 if ((size_t )(b -> rmem_end - b -> rmem_last ) < required_size ) {
345351 /* alloc new rmem page */
346352 * allocated_size = MSGPACK_RMEM_PAGE_SIZE ;
@@ -371,6 +377,7 @@ static inline void* _msgpack_buffer_chunk_malloc(
371377 * allocated_size = required_size ;
372378 void * mem = xmalloc (required_size );
373379 c -> mem = mem ;
380+ c -> rmem = false;
374381 return mem ;
375382}
376383
Original file line number Diff line number Diff line change @@ -78,6 +78,7 @@ struct msgpack_buffer_chunk_t {
7878 void * mem ;
7979 msgpack_buffer_chunk_t * next ;
8080 VALUE mapped_string ; /* RBString or NO_MAPPED_STRING */
81+ bool rmem ;
8182};
8283
8384union msgpack_buffer_cast_block_t {
Original file line number Diff line number Diff line change @@ -86,7 +86,9 @@ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
8686
8787static inline void _msgpack_unpacker_free_stack (msgpack_unpacker_stack_t * stack ) {
8888 #ifdef UNPACKER_STACK_RMEM
89- msgpack_rmem_free (& s_stack_rmem , stack -> data );
89+ if (!msgpack_rmem_free (& s_stack_rmem , stack -> data )) {
90+ rb_bug ("Failed to free an rmem pointer, memory leak?" );
91+ }
9092 #else
9193 xfree (stack -> data );
9294 #endif
You can’t perform that action at this time.
0 commit comments