簡體   English   中英

是libcurl示例httpcustomheader.c越野車(顯示錯誤的做法)還是我錯過了什么?

[英]Is the libcurl example httpcustomheader.c buggy (showing bad practice) or am I missing something?

libcurl示例包含一個自定義HTTP標頭示例

該示例使用curl_slist_append像這樣:

struct curl_slist *chunk = NULL;

/* Remove a header curl would otherwise add by itself */ 
chunk = curl_slist_append(chunk, "Accept:");

/* Add a custom header */ 
chunk = curl_slist_append(chunk, "Another: yes");

/* Modify a header curl otherwise adds differently */ 
chunk = curl_slist_append(chunk, "Host: example.com");

/* Add a header with "blank" contents to the right of the colon. Note that
   we're then using a semicolon in the string we pass to curl! */ 
chunk = curl_slist_append(chunk, "X-silly-header;");

根據curl_slist_append文檔,如果出現問題,將返回空指針:

返回值

如果發生任何錯誤,則返回空指針,否則返回新的列表指針。

題:

例如當電話

chunk = curl_slist_append(chunk, "Another: yes");

失敗,先前指定的那個原始列表不會丟失嗎? 結果:這不會泄漏內存嗎? 還是我缺少某些魔術,而curl_slist_append文檔中沒有提到?

更糟的是:下一次對curl_slist_append的調用是否可能會創建一個新列表(不太可能,因為我們可能已經內存不足,但有可能)嗎?

您的懷疑似乎完全正確。 curl_slist_append的來源可以在這里查看。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM