File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,7 +66,11 @@ void msgpack_buffer_init(msgpack_buffer_t* b)
6666static void _msgpack_buffer_chunk_destroy (msgpack_buffer_chunk_t * c )
6767{
6868 if (c -> mem != NULL ) {
69- if (!msgpack_rmem_free (& s_rmem , c -> mem )) {
69+ if (c -> rmem ) {
70+ if (!msgpack_rmem_free (& s_rmem , c -> mem )) {
71+ rb_bug ("Failed to free an rmem pointer, memory leak?" );
72+ }
73+ } else {
7074 xfree (c -> mem );
7175 }
7276 /* no needs to update rmem_owner because chunks will not be
@@ -349,6 +353,8 @@ static inline void* _msgpack_buffer_chunk_malloc(
349353 size_t required_size , size_t * allocated_size )
350354{
351355 if (required_size <= MSGPACK_RMEM_PAGE_SIZE ) {
356+ c -> rmem = true;
357+
352358 if ((size_t )(b -> rmem_end - b -> rmem_last ) < required_size ) {
353359 /* alloc new rmem page */
354360 * allocated_size = MSGPACK_RMEM_PAGE_SIZE ;
@@ -379,6 +385,7 @@ static inline void* _msgpack_buffer_chunk_malloc(
379385 * allocated_size = required_size ;
380386 void * mem = xmalloc (required_size );
381387 c -> mem = mem ;
388+ c -> rmem = false;
382389 return mem ;
383390}
384391
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