[英]Is the libcurl example httpcustomheader.c buggy (showing bad practice) or am I missing something?
该示例使用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.