- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试运行一个删除链表第 n 个元素的函数(使用从零开始的索引)。即使我不必 malloc 任何东西,我也会收到此错误:“ev(10676,0x7fff73f9d300) malloc: * error for object 0x7fddc2404c10: point being freed was not allocate*在malloc_error_break中设置断点进行调试”
这是代码:
typedef struct intlist intlist;
struct intlist {
int val;
intlist* next;
intlist* intlist_remove_nth(intlist *xs, unsigned int n)
{
int i = 0;
if (n == 1)
{
intlist *tempremovefirst = xs->next;
free(xs);
return tempremovefirst;
}
intlist *temp = xs;
for (temp = xs; i != n - 1; i++)
{
temp = temp->next;
}
intlist *temp2 = temp->next;
temp->next = temp->next->next;
free(temp2);
return xs;
}
void evidence_intlist_remove_nth()
{
intlist *il1 = intlist_cons(1, NULL);
intlist *il2 = intlist_cons(4, il1);
intlist *il3 = intlist_cons(6, il2);
intlist *il4 = intlist_cons(8, il3);
intlist *il5 = intlist_cons(19, il4);
intlist *il6 = intlist_cons(24, il5);
intlist *il7 = intlist_cons(101, il6);
printf("expecting 101 24 19 6 4 1: ");
intlist_print(intlist_remove_nth(il7, 4));
printf("\n");
free(il1);
free(il2);
free(il3);
free(il4);
free(il5);
free(il6);
free(il7);
}
int main(int argc, char *argv[])
{
evidence_intlist_remove_nth();
return 0;
}
最佳答案
如果您没有分配列表中的项目,则不应释放它们。 free()
仅用于释放由 malloc()
或其亲属之一返回的内存。
关于c - "Pointer being freed not allocated error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35530791/
我正在使用套接字并将一些数据写入服务器。第一次连接到服务器时一切正常。但是当它第二次写入,有时是第三次写入时,它会因错误而崩溃: "malloc: *** error for object 0x7c1
给定代码: class Sample { public: int *ptr; Sample(int i) { ptr = new int(i);
#include #include #include #include #include using namespace std; class CFile { public: CFi
很难说出这里问的是什么。这个问题是模棱两可的、模糊的、不完整的、过于宽泛的或修辞的,无法以目前的形式得到合理的回答。为了帮助澄清这个问题以便可以重新打开它,visit the help center
我正在尝试在线找到的四叉树实现,但作为以下(精简的)_node_release 函数的一部分,间歇性地收到“正在释放的指针未分配”错误: static void _node_release(node*
我正在尝试在线找到的四叉树实现,但作为以下(精简的)_node_release 函数的一部分,间歇性地收到“正在释放的指针未分配”错误: static void _node_release(node*
我正在尝试运行一个删除链表第 n 个元素的函数(使用从零开始的索引)。即使我不必 malloc 任何东西,我也会收到此错误:“ev(10676,0x7fff73f9d300) malloc: * er
我正在从标准输入读取内容。由于我不知道要读的内容的长度,所以我必须使用 malloc。 我得到一个被释放的指针未分配 有时,它发生在 free(final) 之前,有时发生在 free(tmp) 之前
我得到一个错误 malloc: *** error for object 0x146f9404: incorrect checksum for freed object - object was
我正在使用 C++ 进行线程处理并进行了一些测试并遇到了这个错误。 这是我的代码: #include #include #include #include #include using na
我有以下功能: void stringcopy(char * to, char const * const from) { int size = 1; while (from[size
每次我想将元素添加到存储类中的 std::map 时,我都会收到错误消息“未分配正在释放的指针”。我在构造函数和析构函数中添加了一些“couts”来调试,输出是: 新的德尔删除 所以看起来析构函数被调
我定义了一个包含字节数组及其长度的结构。析构函数应该只删除字节数组,如果它是由结构的构造函数动态实例化的话。但有时,delete array; 指令失败并出现错误 pointer being free
我正在构建一个 AVL 树。我有一种方法可以删除树中的项目,但出现错误。 这是我得到的运行时错误: malloc: *** error for object 0x100100120: pointer
这是我的功能: void Tetris::place_square(int* coords,char type){ if (coords[1]>heights[coords[0]]){
我创建了一个双链表类,并试图将它与我创建的 Vector 类一起使用,以便制作一个链表 vector ,但是在程序结束时,我似乎遇到了一个错误malloc:对象 0x100100be0 的 *** 错
我想我的 C 现在有点生疏了,因为我不太明白这里的问题。我很确定它位于 parse_historical_data() 中。如果我将其注释掉并运行 allocate_historical_data()
我正在使用 C 语言研究 Segdwick 的算法,并尝试动态链表数组。我在 main 的 return 0 处遇到段错误。我的重点是正确加载和打印链接列表,完成后我没有释放列表数组。 所以我添加了
我正在努力寻找无法释放内存块的原因。指针一定有问题。结构的内存块在函数中创建,使用的指针存储在数组中。稍后从数组中获取指针以用于释放内存。 我已经弄清楚它是免费的了。我在它旁边放了“//这个”。 #i
我正在尝试重载赋值运算符以执行多边形对象的深拷贝,程序编译但我在接近尾声时收到错误,我想清除。以下是相关代码,如果您认为我需要添加更多内容,请发表评论。假设适当的 #include的那 class P
我是一名优秀的程序员,十分优秀!