libcurl示例httpcustomheader.c有bug(显示不良实践)还是我错过了一些东西
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的文档,如果出现错误,将返回空指针:
返回值如果出现任何错误,则返回空指针,否则返回new返回列表指针
问题:
例如调用
chunk = curl_slist_append(chunk, "Another: yes");
失败了,原来的列表,之前指向的块,不会丢失吗?结果是:这不会泄漏内存吗?还是我缺少了一些魔法,而在curl_slist_append文档中没有提到?
更糟糕的是:下次调用curl_slist_append可能不会创建一个新的列表(不太可能,因为我们可能已经没有内存了,但可能)?
你的怀疑似乎完全正确。curl_slist_append
的源代码可以在这里查看。
相关文章:
- gcc 是否在 2 条短裤的过度对齐结构的比较中错过了优化机会?
- 我的C++合并排序代码不起作用。我在这里错过了什么?
- 我是否为邪恶刽子手的构造函数错过了什么?
- C++:将向量传递给函数,然后在main中调用函数.错过了什么
- 随机访问迭代器:我错过了什么?
- 当编译时已知引用占用结构中的空间时,是否错过了优化?
- std::元组大小,是不是错过了优化?
- 在这个while循环中我错过了什么?
- 编译器错过了无效的构造函数调用,并调用不存在的(或私有的)默认构造函数
- 我是否错过了什么,或者虚拟呼叫的性能并不像人们所说的那样糟糕
- C 中MAP的反向迭代错过了第一个元素
- 仅在 2 的幂上错过了 clang 中的优化
- 我错过了boost :: mpi ::请求?测试似乎改变了状态
- 我在变量上收到 3 个 C4703 错误,我认为我已经正确初始化了,但我不确定我错过了什么
- 如果这不是 boost::lockfree::d etail::freelist 中的错误,我在这里错过了什么
- 尝试使用类,但未打印任何内容.不会生成任何错误.我错过了什么吗?
- 尝试实现通过引用传递的向量以与二叉树一起使用,我错过了什么
- c recursive_directory_iterator错过了一些文件
- fgets vs. std :: fgets- fgets错过了线条
- 此代码的输出是什么?我在这里错过了什么吗?