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のドキュメントによると、問題が発生した場合はnullポインタが返されます。
戻り値
何か問題が発生した場合はnullポインターが返され、それ以外の場合は新しいリストポインターが返されます。
質問:
たとえば、電話をかけるとき
chunk = curl_slist_append(chunk, "Another: yes");
失敗します、以前に指し示したそのチャンクである元のリストは失われませんか?そして結果として:これはメモリをリークしませんか?または、私が見逃していて、curl_slist_appendドキュメントに記載されていない魔法がありますか?
さらに悪いことに、curl_slist_appendを次に呼び出すと、新しいリストが作成される可能性はありません(おそらく、すでにメモリが不足している可能性はありますが、可能です)。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加