diff options
author | fadhil riyanto <me@fadev.org> | 2024-09-29 11:22:01 +0700 |
---|---|---|
committer | fadhil riyanto <me@fadev.org> | 2024-09-29 11:22:01 +0700 |
commit | 08882a27f6f24e95daef413b6b5e5b4a759550e4 (patch) | |
tree | 14c0d41b92f93f04602423b3197cc7e786d3c82b | |
parent | 45e9c0223b654c80df833d36533c9f2303a101e2 (diff) |
fix sigsegv: init_get_pthread_arrptr
func init_get_pthread_arrptr return pthread_t* where this ptr is
dynamic mem. this cause rewrite already mapped memory
also add pthread_join
Signed-off-by: fadhil riyanto <me@fadev.org>
-rw-r--r-- | main.c | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -300,6 +300,7 @@ static int add_fd_sockaddr(struct fd_sockaddr_list *fdsocklist, *fdsocklist->list[fdsocklist->size - 1].sockaddr = *sockaddr; fdsocklist->list[fdsocklist->size - 1].fd = fd; fdsocklist->list[fdsocklist->size - 1].is_active = 1; + fdsocklist->list[fdsocklist->size - 1].private_conn_thread = NULL; fdsocklist->size = fdsocklist->size + 1; @@ -350,13 +351,20 @@ static void mark_conn_inactive(struct fd_sockaddr_list *fdsocklist, static pthread_t* init_get_pthread_arrptr(struct fd_sockaddr_list *fdsocklist, int fd_num) { + void *retval; + for(int i = 0; i < fdsocklist->size; i++) { if (fdsocklist->list[i].is_active == 1 && fdsocklist->list[i].fd == fd_num) { - - fdsocklist->list[i].private_conn_thread = (pthread_t*)malloc( - sizeof(pthread_t) - ); + + if (fdsocklist->list[i].private_conn_thread == NULL) { + fdsocklist->list[i].private_conn_thread = (pthread_t*)malloc( + sizeof(pthread_t) + ); + } else { + pthread_join(*fdsocklist->list[i].private_conn_thread, &retval); + } + return fdsocklist->list[i].private_conn_thread; } @@ -491,9 +499,11 @@ static void* start_private_conn(void* start_private_conn_details) close(current_fd); */ - /* call when send error in future */ - mark_conn_inactive(srv_ctx->fd_sockaddr_list, - current_fd); + /* call when send error in future, can cause SIGSEGV because init_get_pthread_arrptr check + conn is active or not */ + + // mark_conn_inactive(srv_ctx->fd_sockaddr_list, + // current_fd); } static void* start_long_poll_receiver(void *srv_ctx_voidptr) |