1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

ST: Support st_destroy to free resources for asan.

This commit is contained in:
chengh 2022-11-21 22:26:46 +08:00 committed by winlin
parent 6eb10afca2
commit 6fa17aa3f8
5 changed files with 39 additions and 4 deletions

View file

@ -118,6 +118,7 @@ The branch [srs](https://github.com/ossrs/state-threads/tree/srs) was patched an
- [x] Define and use a new jmpbuf, because the structure is different. - [x] Define and use a new jmpbuf, because the structure is different.
- [x] Check capability for backtrack. - [x] Check capability for backtrack.
- [x] Support set specifics for any thread. - [x] Support set specifics for any thread.
- [x] Support st_destroy to free resources for asan.
- [ ] System: Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12). - [ ] System: Support sendmmsg for UDP, [#12](https://github.com/ossrs/state-threads/issues/12).
## GDB Tools ## GDB Tools

View file

@ -226,6 +226,7 @@ typedef struct _st_eventsys_ops {
int (*fd_new)(int); /* New descriptor allocated */ int (*fd_new)(int); /* New descriptor allocated */
int (*fd_close)(int); /* Descriptor closed */ int (*fd_close)(int); /* Descriptor closed */
int (*fd_getlimit)(void); /* Descriptor hard limit */ int (*fd_getlimit)(void); /* Descriptor hard limit */
void (*destroy)(void); /* Destroy the event object */
} _st_eventsys_t; } _st_eventsys_t;

View file

@ -430,6 +430,11 @@ ST_HIDDEN int _st_select_fd_getlimit(void)
return FD_SETSIZE; return FD_SETSIZE;
} }
ST_HIDDEN void _st_select_destroy(void)
{
/* TODO: FIXME: Implements it */
}
static _st_eventsys_t _st_select_eventsys = { static _st_eventsys_t _st_select_eventsys = {
"select", "select",
ST_EVENTSYS_SELECT, ST_EVENTSYS_SELECT,
@ -439,7 +444,8 @@ static _st_eventsys_t _st_select_eventsys = {
_st_select_pollset_del, _st_select_pollset_del,
_st_select_fd_new, _st_select_fd_new,
_st_select_fd_close, _st_select_fd_close,
_st_select_fd_getlimit _st_select_fd_getlimit,
_st_select_destroy
}; };
#endif #endif
@ -838,6 +844,11 @@ ST_HIDDEN int _st_kq_fd_getlimit(void)
return 0; return 0;
} }
ST_HIDDEN void _st_kq_destroy(void)
{
/* TODO: FIXME: Implements it */
}
static _st_eventsys_t _st_kq_eventsys = { static _st_eventsys_t _st_kq_eventsys = {
"kqueue", "kqueue",
ST_EVENTSYS_ALT, ST_EVENTSYS_ALT,
@ -847,7 +858,8 @@ static _st_eventsys_t _st_kq_eventsys = {
_st_kq_pollset_del, _st_kq_pollset_del,
_st_kq_fd_new, _st_kq_fd_new,
_st_kq_fd_close, _st_kq_fd_close,
_st_kq_fd_getlimit _st_kq_fd_getlimit,
_st_kq_destroy
}; };
#endif /* MD_HAVE_KQUEUE */ #endif /* MD_HAVE_KQUEUE */
@ -856,7 +868,6 @@ static _st_eventsys_t _st_kq_eventsys = {
/***************************************** /*****************************************
* epoll event system * epoll event system
*/ */
ST_HIDDEN int _st_epoll_init(void) ST_HIDDEN int _st_epoll_init(void)
{ {
int fdlim; int fdlim;
@ -1193,6 +1204,17 @@ ST_HIDDEN int _st_epoll_is_supported(void)
return (errno != ENOSYS); return (errno != ENOSYS);
} }
ST_HIDDEN void _st_epoll_destroy(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 = { static _st_eventsys_t _st_epoll_eventsys = {
"epoll", "epoll",
ST_EVENTSYS_ALT, ST_EVENTSYS_ALT,
@ -1202,7 +1224,8 @@ static _st_eventsys_t _st_epoll_eventsys = {
_st_epoll_pollset_del, _st_epoll_pollset_del,
_st_epoll_fd_new, _st_epoll_fd_new,
_st_epoll_fd_close, _st_epoll_fd_close,
_st_epoll_fd_getlimit _st_epoll_fd_getlimit,
_st_epoll_destroy
}; };
#endif /* MD_HAVE_EPOLL */ #endif /* MD_HAVE_EPOLL */

View file

@ -156,6 +156,7 @@ extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_uti
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode); extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);
extern void st_destroy(void);
extern int st_thread_setspecific2(st_thread_t thread, int key, void *value); extern int st_thread_setspecific2(st_thread_t thread, int key, void *value);
#ifdef DEBUG #ifdef DEBUG

View file

@ -229,6 +229,15 @@ int st_init(void)
} }
/*
* Destroy this Virtual Processor
*/
void st_destroy(void)
{
(*_st_eventsys->destroy)();
}
#ifdef ST_SWITCH_CB #ifdef ST_SWITCH_CB
st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb) st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb)
{ {