【发布时间】:2015-10-14 02:02:32
【问题描述】:
我觉得使用动态类型语言已经破坏了我对此的直觉!
假设我 malloc 为一个字符串留出空间,然后用另一个 malloc 更新该指针(它使用第一个数据),这是内存泄漏吗?
char* my_string = (char*)malloc(length + 1);
(void)snprintf(my_string, length, "blah...");
my_string = some_manipulation(my_string);
我们有 char* some_manipulation(const char* str); 为其输出分配内存,这是从提供的参数生成的(并且可能长度不同)。
第一个malloc 现在是否丢失,但占用空间,直到退出?
【问题讨论】:
标签: c memory-leaks malloc dynamic-memory-allocation