From 7d11704ed9c379095678e8a281d715f2e912565a Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 9 Jun 2026 16:12:08 +0200 Subject: [PATCH] refactor: move curl_free at the end --- compile.sh | 2 +- main.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compile.sh b/compile.sh index 5c59b2d..72d3581 100755 --- a/compile.sh +++ b/compile.sh @@ -1,2 +1,2 @@ -gcc main.c -o bot $(pkgconf --libs libcurl) $(pkgconf --libs yyjson) +gcc main.c -o bot $(pkgconf --libs libcurl yyjson) ./bot YOUR_TOKEN_HERE diff --git a/main.c b/main.c index 6b73e88..fcc7abc 100644 --- a/main.c +++ b/main.c @@ -24,10 +24,11 @@ void send_message(tgbot *bot, tgmessage *message) { char *encoded_text = curl_easy_escape(bot->curl, message->text, 0); snprintf(url, sizeof(url), "%ssendMessage?chat_id=%ld&text=%s", bot->api, message->chat_id, encoded_text); - curl_free(encoded_text); curl_easy_setopt(bot->curl, CURLOPT_URL, url); curl_easy_perform(bot->curl); + + curl_free(encoded_text); } size_t write_cb(void *ptr, size_t size, size_t nmemb, char *data) {