refactor: move curl_free at the end

This commit is contained in:
2026-06-09 16:12:08 +02:00
parent bb5ea15f54
commit 7d11704ed9
2 changed files with 3 additions and 2 deletions
+1 -1
View File
@@ -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 ./bot YOUR_TOKEN_HERE
+2 -1
View File
@@ -24,10 +24,11 @@ void send_message(tgbot *bot, tgmessage *message) {
char *encoded_text = curl_easy_escape(bot->curl, message->text, 0); char *encoded_text = curl_easy_escape(bot->curl, message->text, 0);
snprintf(url, sizeof(url), "%ssendMessage?chat_id=%ld&text=%s", bot->api, snprintf(url, sizeof(url), "%ssendMessage?chat_id=%ld&text=%s", bot->api,
message->chat_id, encoded_text); message->chat_id, encoded_text);
curl_free(encoded_text);
curl_easy_setopt(bot->curl, CURLOPT_URL, url); curl_easy_setopt(bot->curl, CURLOPT_URL, url);
curl_easy_perform(bot->curl); curl_easy_perform(bot->curl);
curl_free(encoded_text);
} }
size_t write_cb(void *ptr, size_t size, size_t nmemb, char *data) { size_t write_cb(void *ptr, size_t size, size_t nmemb, char *data) {