docs: handle error in curl_global_init* examples

Also:
- call cleanup in `curl_global_init_mem()` example.

Closes #20866
This commit is contained in:
Viktor Szakats 2026-03-09 11:04:24 +01:00
parent f6840572c4
commit df5c6b6f54
No known key found for this signature in database
2 changed files with 20 additions and 6 deletions

View file

@ -117,11 +117,16 @@ elapses.
~~~c
int main(void)
{
curl_global_init(CURL_GLOBAL_DEFAULT);
CURLcode result;
/* use libcurl, then before exiting... */
result = curl_global_init(CURL_GLOBAL_DEFAULT);
curl_global_cleanup();
if(result == CURLE_OK) {
/* use libcurl, then before exiting... */
curl_global_cleanup();
}
}
~~~

View file

@ -84,9 +84,18 @@ extern void *calloc_cb(size_t, size_t);
int main(void)
{
curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
free_cb, realloc_cb,
strdup_cb, calloc_cb);
CURLcode result;
result = curl_global_init_mem(CURL_GLOBAL_DEFAULT, malloc_cb,
free_cb, realloc_cb,
strdup_cb, calloc_cb);
if(result == CURLE_OK) {
/* use libcurl, then before exiting... */
curl_global_cleanup();
}
}
~~~