fix parise may cause segfault

This commit is contained in:
2024-09-09 14:29:36 +08:00
parent 3f064f651c
commit 1e3d3e5a83

7
main.c
View File

@@ -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&timestamp=%llu"; const char URL[] = "https://zhibo.chaoxing.com/apis/live/setLivePariseCountByEnc?subroomId=%s&enc=%s&timestamp=%llu";
const char SUBROOMID[] = "381236458034402305"; const char SUBROOMID[] = "381236458034402305";
const char SS[] = "381237373432790016"; const char SS[] = "381237373432790016";
const char DNS[] = "8.8.8.8:53,114.114.114.114:53";
static int flag = 1; static int flag = 1;
int main(int argc, char *argv[]) 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"); "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_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_DNS_SERVERS, DNS);
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USE_SSL, true); curl_easy_setopt(curl, CURLOPT_USE_SSL, true);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, cb);
@@ -190,7 +192,9 @@ void parise(void *arg)
continue; continue;
REGEN_URL_F(url, enc.enc, enc.timestamp); 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); json = cJSON_Parse(json_c.response);
result = cJSON_GetObjectItemCaseSensitive(json, "result"); result = cJSON_GetObjectItemCaseSensitive(json, "result");
@@ -204,6 +208,7 @@ void parise(void *arg)
fprintf(stderr, "\rT%d\t%s", idx, errorMsg->valuestring); fprintf(stderr, "\rT%d\t%s", idx, errorMsg->valuestring);
fflush(stdout); fflush(stdout);
clean:
free(enc.enc); free(enc.enc);
free(json_c.response); free(json_c.response);
cJSON_Delete(json); cJSON_Delete(json);