Skip to content

Commit

Permalink
fix: fix memory leak in tls_transient_memory_t (#422)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhao liwei authored Mar 23, 2020
1 parent 67012ed commit 9b4cae8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion include/dsn/utility/transient_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ namespace dsn {

typedef struct tls_transient_memory_t
{
~tls_transient_memory_t()
{
if (nullptr != block) {
*block = nullptr;
}
}

unsigned int magic;
size_t remain_bytes;
char block_ptr_buffer[sizeof(std::shared_ptr<char>)];
Expand All @@ -59,7 +66,7 @@ typedef struct tls_transient_memory_t
bool committed;
} tls_transient_memory_t;

extern __thread tls_transient_memory_t tls_trans_memory;
extern thread_local tls_transient_memory_t tls_trans_memory;

// initialize the default block size, should call this at the beginning of the process
void tls_trans_mem_init(size_t default_per_block_bytes);
Expand Down
2 changes: 1 addition & 1 deletion src/core/core/transient_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

namespace dsn {

__thread tls_transient_memory_t tls_trans_memory;
thread_local tls_transient_memory_t tls_trans_memory;

static size_t tls_trans_mem_default_block_bytes = 1024 * 1024; // 1 MB

Expand Down

0 comments on commit 9b4cae8

Please sign in to comment.