Skip to content

Commit

Permalink
asan: try to fix st_memory_leak for asan check
Browse files Browse the repository at this point in the history
  • Loading branch information
chen-guanghua committed Nov 21, 2022
1 parent 9191217 commit ecc438d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions trunk/3rdparty/st-srs/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ typedef struct _st_eventsys_ops {
int (*fd_new)(int); /* New descriptor allocated */
int (*fd_close)(int); /* Descriptor closed */
int (*fd_getlimit)(void); /* Descriptor hard limit */
void (*uninit)(void); /* UnInitialization*/
} _st_eventsys_t;


Expand Down
29 changes: 25 additions & 4 deletions trunk/3rdparty/st-srs/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ ST_HIDDEN int _st_select_fd_getlimit(void)
return FD_SETSIZE;
}

ST_HIDDEN void _st_select_uninit(void)
{
}

static _st_eventsys_t _st_select_eventsys = {
"select",
ST_EVENTSYS_SELECT,
Expand All @@ -439,7 +443,8 @@ static _st_eventsys_t _st_select_eventsys = {
_st_select_pollset_del,
_st_select_fd_new,
_st_select_fd_close,
_st_select_fd_getlimit
_st_select_fd_getlimit,
_st_select_uninit
};
#endif

Expand Down Expand Up @@ -838,6 +843,10 @@ ST_HIDDEN int _st_kq_fd_getlimit(void)
return 0;
}

ST_HIDDEN void _st_kq_uninit(void)
{
}

static _st_eventsys_t _st_kq_eventsys = {
"kqueue",
ST_EVENTSYS_ALT,
Expand All @@ -847,7 +856,8 @@ static _st_eventsys_t _st_kq_eventsys = {
_st_kq_pollset_del,
_st_kq_fd_new,
_st_kq_fd_close,
_st_kq_fd_getlimit
_st_kq_fd_getlimit,
_st_kq_uninit
};
#endif /* MD_HAVE_KQUEUE */

Expand All @@ -856,7 +866,6 @@ static _st_eventsys_t _st_kq_eventsys = {
/*****************************************
* epoll event system
*/

ST_HIDDEN int _st_epoll_init(void)
{
int fdlim;
Expand Down Expand Up @@ -1193,6 +1202,17 @@ ST_HIDDEN int _st_epoll_is_supported(void)
return (errno != ENOSYS);
}

ST_HIDDEN void _st_epoll_uninit(void)
{
if (_st_epoll_data->epfd >= 0) {
close(_st_epoll_data->epfd);
}
free(_st_epoll_data->fd_data);
free(_st_epoll_data->evtlist);
free(_st_epoll_data);
_st_epoll_data = NULL;
}

static _st_eventsys_t _st_epoll_eventsys = {
"epoll",
ST_EVENTSYS_ALT,
Expand All @@ -1202,7 +1222,8 @@ static _st_eventsys_t _st_epoll_eventsys = {
_st_epoll_pollset_del,
_st_epoll_fd_new,
_st_epoll_fd_close,
_st_epoll_fd_getlimit
_st_epoll_fd_getlimit,
_st_epoll_uninit
};
#endif /* MD_HAVE_EPOLL */

Expand Down
1 change: 1 addition & 0 deletions trunk/3rdparty/st-srs/public.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ typedef void (*st_switch_cb_t)(void);

extern int st_init(void);
extern int st_getfdlimit(void);
extern void st_uninit(void);

extern int st_set_eventsys(int eventsys);
extern int st_get_eventsys(void);
Expand Down
4 changes: 4 additions & 0 deletions trunk/3rdparty/st-srs/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ int st_init(void)
return 0;
}

void st_uninit(void)
{
(*_st_eventsys->uninit)();
}

#ifdef ST_SWITCH_CB
st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb)
Expand Down
4 changes: 3 additions & 1 deletion trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ srs_error_t do_main(int argc, char** argv, char** envp)
if ((err = run_directly_or_daemon()) != srs_success) {
return srs_error_wrap(err, "run");
}


srs_st_uninit();

return err;
}

Expand Down
6 changes: 6 additions & 0 deletions trunk/src/protocol/srs_protocol_st.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ srs_error_t srs_st_init()
return srs_success;
}

void srs_st_uninit(void)
{
srs_trace("st_uninit success, use %s", st_get_eventsys_name());
st_uninit();
}

void srs_close_stfd(srs_netfd_t& stfd)
{
if (stfd) {
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/protocol/srs_protocol_st.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ typedef void* srs_mutex_t;

// Initialize st, requires epoll.
extern srs_error_t srs_st_init();
// UnInitialize st
extern void srs_st_uninit(void);

// Close the netfd, and close the underlayer fd.
// @remark when close, user must ensure io completed.
Expand Down

0 comments on commit ecc438d

Please sign in to comment.