-
-
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
SmartPtr: Support detect memory leak by valgrind. v6.0.132 #4102
Conversation
winlinvip
commented
Jun 21, 2024
•
edited
Loading
edited
- Support detect memory leak by valgrind.
- Free the http handler entry.
- Free the stack of ST.
9476ab2
to
adcfb37
Compare
@@ -191,6 +191,9 @@ endif | |||
# | |||
# 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.
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
to st-srs
, like MD_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.
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
@@ -72,14 +74,34 @@ _st_stack_t *_st_stack_new(int stack_size) | |||
_st_num_free_stacks--; | |||
ts->links.next = NULL; | |||
ts->links.prev = NULL; | |||
return ts; | |||
returnt ts; |
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.
is it a mistake? returnt
-> return
.
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.
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
# Patched ST from https://github.com/ossrs/state-threads/tree/srs | |
if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/libst.a ]]; then | |
rm -rf ${SRS_OBJS}/st && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/ && | |
echo "The state-threads is ok." | |
else | |
echo "Building state-threads." && | |
rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/st && | |
cp -rf ${SRS_WORKDIR}/3rdparty/st-srs ${SRS_OBJS}/${SRS_PLATFORM}/ && | |
env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" make -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} && | |
mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st && | |
cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/st.h ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/ && | |
cp -f ${SRS_OBJS}/${SRS_PLATFORM}/st-srs/${_ST_OBJ}/libst.a ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st/ && | |
cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdparty/st ${SRS_OBJS}/ && | |
echo "The state-threads is ok." | |
fi |
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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