From 1e3d3e5a837a78bb38447269993a1eaa7f37bcf3 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Mon, 9 Sep 2024 14:29:36 +0800 Subject: [PATCH] fix parise may cause segfault --- main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 6549ae9..3cfc852 100644 --- a/main.c +++ b/main.c @@ -49,6 +49,7 @@ const char ENC_URL[] = "https://lbapi-rk.chaoxing.com/lb/parise/enc/get?subRoomI const char URL[] = "https://zhibo.chaoxing.com/apis/live/setLivePariseCountByEnc?subroomId=%s&enc=%s×tamp=%llu"; const char SUBROOMID[] = "381236458034402305"; const char SS[] = "381237373432790016"; +const char DNS[] = "8.8.8.8:53,114.114.114.114:53"; static int flag = 1; int main(int argc, char *argv[]) @@ -103,6 +104,7 @@ CURLcode curl_get(const char *const url, struct memory *chunk) "Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, DNS); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_USE_SSL, true); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb); @@ -190,7 +192,9 @@ void parise(void *arg) continue; REGEN_URL_F(url, enc.enc, enc.timestamp); - curl_get(url, &json_c); + + if (curl_get(url, &json_c) != CURLE_OK) + goto clean; json = cJSON_Parse(json_c.response); result = cJSON_GetObjectItemCaseSensitive(json, "result"); @@ -204,6 +208,7 @@ void parise(void *arg) fprintf(stderr, "\rT%d\t%s", idx, errorMsg->valuestring); fflush(stdout); + clean: free(enc.enc); free(json_c.response); cJSON_Delete(json);