Skip to content

Commit

Permalink
Support st_destroy to free resources for asan.
Browse files Browse the repository at this point in the history
  • Loading branch information
chen-guanghua authored and winlinvip committed Nov 21, 2022
1 parent 354df60 commit 843e74b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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] Check capability for backtrack.
- [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).

## GDB Tools
Expand Down
1 change: 1 addition & 0 deletions 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 (*destroy)(void); /* Destroy the event object */
} _st_eventsys_t;


Expand Down
31 changes: 27 additions & 4 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,11 @@ ST_HIDDEN int _st_select_fd_getlimit(void)
return FD_SETSIZE;
}

ST_HIDDEN void _st_select_destroy(void)
{
/* TODO: FIXME: Implements it */
}

static _st_eventsys_t _st_select_eventsys = {
"select",
ST_EVENTSYS_SELECT,
Expand All @@ -439,7 +444,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_destroy
};
#endif

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

ST_HIDDEN void _st_kq_destroy(void)
{
/* TODO: FIXME: Implements it */
}

static _st_eventsys_t _st_kq_eventsys = {
"kqueue",
ST_EVENTSYS_ALT,
Expand All @@ -847,7 +858,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_destroy
};
#endif /* MD_HAVE_KQUEUE */

Expand All @@ -856,7 +868,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 +1204,17 @@ ST_HIDDEN int _st_epoll_is_supported(void)
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 = {
"epoll",
ST_EVENTSYS_ALT,
Expand All @@ -1202,7 +1224,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_destroy
};
#endif /* MD_HAVE_EPOLL */

Expand Down
1 change: 1 addition & 0 deletions public.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 void st_destroy(void);
extern int st_thread_setspecific2(st_thread_t thread, int key, void *value);

#ifdef DEBUG
Expand Down
9 changes: 9 additions & 0 deletions sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ int st_init(void)
}


/*
* Destroy this Virtual Processor
*/
void st_destroy(void)
{
(*_st_eventsys->destroy)();
}


#ifdef ST_SWITCH_CB
st_switch_cb_t st_set_switch_in_cb(st_switch_cb_t cb)
{
Expand Down

0 comments on commit 843e74b

Please sign in to comment.