From 74ac922c53df21a803c556da8616e466887c4fe0 Mon Sep 17 00:00:00 2001 From: Raw Monk Date: Tue, 14 Jun 2022 16:17:26 -0400 Subject: [PATCH] quick fix to keep tab address in thread --- src/gemini.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gemini.c b/src/gemini.c index 14d7513..113615d 100644 --- a/src/gemini.c +++ b/src/gemini.c @@ -781,7 +781,7 @@ struct gmi_tab* gmi_newtab() { } struct gmi_tab* gmi_newtab_url(const char* url) { - int index = client.tabs_count; + size_t index = client.tabs_count; client.tabs_count++; if (client.tabs) client.tabs = realloc(client.tabs, sizeof(struct gmi_tab) * client.tabs_count); @@ -793,7 +793,8 @@ struct gmi_tab* gmi_newtab_url(const char* url) { if (socketpair(AF_UNIX, SOCK_STREAM, 0, tab->thread.pair)) return NULL; - pthread_create(&tab->thread.thread, NULL, (void *(*)(void *))gmi_request_thread, tab); + pthread_create(&tab->thread.thread, NULL, + (void *(*)(void *))gmi_request_thread, (void*)index); tab->thread.started = 1; if (url) gmi_request(tab, url, 1); @@ -1368,7 +1369,8 @@ int gmi_request_body(struct gmi_tab* tab) { } void* gmi_request_thread(void* ptr) { - struct gmi_tab* tab = ptr; + size_t index = (size_t)ptr; +#define tab (&client.tabs[index]) unsigned int signal = 0; while (!client.shutdown) { tab->selected = 0; @@ -1609,6 +1611,7 @@ void* gmi_request_thread(void* ptr) { tab->request.recv = tab->page.data_len; } } +#undef tab return NULL; }