SmartPtr: Support detect memory leak by valgrind. v6.0.132#4102
SmartPtr: Support detect memory leak by valgrind. v6.0.132#4102winlinvip merged 6 commits intoossrs:developfrom
Conversation
9476ab2 to
adcfb37
Compare
| # make EXTRA_CFLAGS=-DDEBUG_STATS | ||
| # | ||
| # or cache the stack and reuse it: | ||
| # make EXTRA_CFLAGS=-DMD_CACHE_STACK |
There was a problem hiding this comment.
why not add configure args to bypass MD_CACHE_STACK to st-srs, like MD_VALGRIND?
There was a problem hiding this comment.
I want to not cache the stack by default, while this macro is used to enable the stack cache.
Won't fix.
|
Here is my env to testing & verify valgrind memory leak, there are a lot of outputs need to analysis, so I align my test env here. Because I didn't find an image with valgrind in https://hub.docker.com/r/ossrs/srs/tags, I make my own one based on I would suggest tag an image with all the testing tools to the srs public docker hub. Then build srs: (
and run the srs with valgrind:
do live streams publish and play, close the srs by |
trunk/3rdparty/st-srs/stk.c
Outdated
| ts->links.next = NULL; | ||
| ts->links.prev = NULL; | ||
| return ts; | ||
| returnt ts; |
There was a problem hiding this comment.
is it a mistake? returnt -> return.
There was a problem hiding this comment.
It's a mistake.
To reproduce, I need to add -DMD_CACHE_STACK to auto/depends.sh, run make clean_st, then ./configure && make.
Lines 283 to 297 in ea7e2c2
st-srs never spend too much time to build, maybe need to consider whether it's a good idea to build st-srs in this inconvenient way.
There was a problem hiding this comment.
Fixed.
BTW: You can use configure to enable the macro:
./configure -h |grep flags
# --extra-flags=<EFLAGS> Set EFLAGS as CFLAGS and CXXFLAGS. Also passed to ST as EXTRA_CFLAGS.
By this way, I found another definitely memory leak: srs/trunk/src/app/srs_app_ingest.cpp Lines 89 to 106 in ea7e2c2
|
| _st_delete_stk_segment(ts->vaddr, ts->vaddr_size); | ||
| free(ts); | ||
| } | ||
| #endif |
There was a problem hiding this comment.
only rarely a few part of codes in st-srs, add comments to denote which #if to match.
| #endif | |
| #endif /* MD_CACHE_STACK */ |
I would suggest add comments in this way.
| #endif | ||
|
|
||
| extra = _st_randomize_stacks ? _ST_PAGE_SIZE : 0; | ||
| #ifndef MD_CACHE_STACK |
There was a problem hiding this comment.
if don't cache stack, why not free _st_stack_t in _st_stack_free, don't use _st_free_stacks to store the freed stack?
The stack still not freed in _st_free_stacks, else a new coroutine started and request a new stack here.
There was a problem hiding this comment.
The crash appears to occur when the st is freed within the _st_stack_free function, which seems to be happening while the stack is still in use. Although it is added to the _st_free_stacks structure, and the previous st is released before the next coroutine starts, this approach should not result in a significant memory leak issue.
Won't fix.
TRANS_BY_GPT4
Uh oh!
There was an error while loading. Please reload this page.