-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SmartPtr: Support detect memory leak by valgrind. v6.0.132 #4102
Changes from all commits
30eded4
adcfb37
69f1998
ca3eaf1
ff9b0fb
3efecaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -57,13 +57,15 @@ __thread int _st_num_free_stacks = 0; | |||||
__thread int _st_randomize_stacks = 0; | ||||||
|
||||||
static char *_st_new_stk_segment(int size); | ||||||
static void _st_delete_stk_segment(char *vaddr, int size); | ||||||
|
||||||
_st_stack_t *_st_stack_new(int stack_size) | ||||||
{ | ||||||
_st_clist_t *qp; | ||||||
_st_stack_t *ts; | ||||||
int extra; | ||||||
|
||||||
|
||||||
#ifdef MD_CACHE_STACK | ||||||
for (qp = _st_free_stacks.next; qp != &_st_free_stacks; qp = qp->next) { | ||||||
ts = _ST_THREAD_STACK_PTR(qp); | ||||||
if (ts->stk_size >= stack_size) { | ||||||
|
@@ -75,11 +77,31 @@ _st_stack_t *_st_stack_new(int stack_size) | |||||
return ts; | ||||||
} | ||||||
} | ||||||
#endif | ||||||
|
||||||
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0; | ||||||
#ifndef MD_CACHE_STACK | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if don't cache stack, why not free There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The crash appears to occur when the Won't fix.
|
||||||
for (qp = _st_free_stacks.next; qp != &_st_free_stacks;) { | ||||||
ts = _ST_THREAD_STACK_PTR(qp); | ||||||
// Before qp is freed, move to next one, because the qp will be freed when free the ts. | ||||||
qp = qp->next; | ||||||
|
||||||
ST_REMOVE_LINK(&ts->links); | ||||||
_st_num_free_stacks--; | ||||||
|
||||||
#if defined(DEBUG) && !defined(MD_NO_PROTECT) | ||||||
mprotect(ts->vaddr, REDZONE, PROT_READ | PROT_WRITE); | ||||||
mprotect(ts->stk_top + extra, REDZONE, PROT_READ | PROT_WRITE); | ||||||
#endif | ||||||
|
||||||
_st_delete_stk_segment(ts->vaddr, ts->vaddr_size); | ||||||
free(ts); | ||||||
} | ||||||
#endif | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only rarely a few part of codes in
Suggested change
I would suggest add comments in this way. |
||||||
|
||||||
/* Make a new thread stack object. */ | ||||||
if ((ts = (_st_stack_t *)calloc(1, sizeof(_st_stack_t))) == NULL) | ||||||
return NULL; | ||||||
extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0; | ||||||
ts->vaddr_size = stack_size + 2*REDZONE + extra; | ||||||
ts->vaddr = _st_new_stk_segment(ts->vaddr_size); | ||||||
if (!ts->vaddr) { | ||||||
|
@@ -114,7 +136,7 @@ void _st_stack_free(_st_stack_t *ts) | |||||
{ | ||||||
if (!ts) | ||||||
return; | ||||||
|
||||||
/* Put the stack on the free list */ | ||||||
ST_APPEND_LINK(&ts->links, _st_free_stacks.prev); | ||||||
_st_num_free_stacks++; | ||||||
|
@@ -152,8 +174,6 @@ static char *_st_new_stk_segment(int size) | |||||
} | ||||||
|
||||||
|
||||||
/* Not used */ | ||||||
#if 0 | ||||||
void _st_delete_stk_segment(char *vaddr, int size) | ||||||
winlinvip marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
{ | ||||||
#ifdef MALLOC_STACK | ||||||
|
@@ -162,7 +182,6 @@ void _st_delete_stk_segment(char *vaddr, int size) | |||||
(void) munmap(vaddr, size); | ||||||
#endif | ||||||
} | ||||||
#endif | ||||||
|
||||||
int st_randomize_stacks(int on) | ||||||
{ | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ udp-server | |
udp-client | ||
cost | ||
cost.log | ||
thread-join |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
g++ thread-join.cpp ../../objs/st/libst.a -g -O0 -o thread-join && ./thread-join | ||
*/ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include "../../objs/st/st.h" | ||
|
||
void* pfn(void* arg) { | ||
printf("pid=%d, coroutine is ok\n", ::getpid()); | ||
return NULL; | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
st_init(); | ||
|
||
printf("pid=%d, create coroutine #1\n", ::getpid()); | ||
st_thread_t thread = st_thread_create(pfn, NULL, 1, 0); | ||
st_thread_join(thread, NULL); | ||
|
||
st_usleep(100 * 1000); | ||
|
||
printf("pid=%d, create coroutine #2\n", ::getpid()); | ||
thread = st_thread_create(pfn, NULL, 1, 0); | ||
st_thread_join(thread, NULL); | ||
|
||
st_usleep(100 * 1000); | ||
|
||
printf("pid=%d, create coroutine #3\n", ::getpid()); | ||
thread = st_thread_create(pfn, NULL, 1, 0); | ||
st_thread_join(thread, NULL); | ||
|
||
printf("done\n"); | ||
st_thread_exit(NULL); | ||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not add configure args to bypass
MD_CACHE_STACK
tost-srs
, likeMD_VALGRIND
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to not cache the stack by default, while this macro is used to enable the stack cache.
Won't fix.