- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
所以当我运行我的代码时,我一直遇到这个错误:free(): invalid next size(fast)
。如果我删除函数末尾的 free,我知道我正在泄漏内存,但我不明白为什么会出现此错误。
我认为这与我错误地分配内存有关,但我似乎找不到解决方法,这是我的代码:
bool parse(const char* line) //NOT WORKING JUST QUITE
{
char* copy = malloc(sizeof(line)); //allocate space for a copy of the line parameter
strcpy(copy, line); //copy the line parameter
char* method = strtok(copy, " "); //pointer to the method
char* reqLine = strtok(NULL, " "); //pointer to the requestline
char* version = strtok(NULL, "\r\n"); //pointer to the HTTP-Version
if (strcmp(method,"GET") != 0) //if the method is not GET
{
printf("%s\n", method);
printf("ERROR 405\n");
return false;
}
if (strncmp(reqLine, "/", 1) != 0)//if the request line does not begin with a / character
{
printf("%c\n", reqLine[0]);
printf("%s\n", reqLine);
printf("ERROR 501\n");
return false;
}
if (strchr(reqLine, 34) != NULL) //if the request line contains a " character
{
printf("%s\n", reqLine);
printf("ERROR 400\n");
return false;
}
if (strcmp(version, "HTTP/1.1") != 0)
{
printf("%s", version);
printf("ERROR 505\n");
return false;
}
//free(copy);
return true;
}
如果有帮助,传入的 const char*
行的形式为:
method
SP request-target SP HTTP-version CRLF
其中SP为空格,CRLF为回车换行。
最佳答案
改变这个:
char* copy = malloc(sizeof(line));
为此:
char* copy = malloc(strlen(line) + 1);
第一个为line
的大小分配空间,这是一个POINTER!
而第二个,分配空间等于 line
指向的字符串的长度,加一,用于 NULL 终止符(请不要忘记和你会过上更幸福的生活c -生活)! ;)
顺便说一句,我认为将代码注释写在代码行上方(而不是旁边)更为常见。 :)
关于c - 免费(): invalid next size (fast) error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39113727/
我有一个 mysql 数据库,用户可以在其中输入文本。然后他们需要能够搜索此文本。我刚刚实现了 mysql 全文搜索,它确实使搜索速度快了很多。 然而,毫不奇怪,它使插入变慢了。但令我惊讶的是速度慢了
我在 Linux 3.15 机器上写了一个 TCP 客户端,它能够使用 TCP Fast Open: status = sendto(sd, (const void *) data,
“free(): invalid next size (fast)”中的“fast”或“normal”是什么意思:谁能解释一下这是什么意思/暗示或在哪里可以找到答案? 最佳答案 您看到的错误消息表明在
像 FAST 这样的数据编码协议(protocol)非常巧妙地减少了需要发送的数据量。本质上,一个人得到一个 char*,读取前几个字节作为整数会给你一个 ID 号,它指向你如何解码其余字节的说明(即
语境 我非常喜欢Roy Osherove所说的“快速集成测试”。这是集成测试,它可以: 严格在您的开发箱上执行。无需单独的环境。 尽管正在进行集成测试,但此类测试通常是通过您的单元测试工具(NUnit
我的代码中有一些子例程,我需要测量它们的执行时间。让我们假设例程在极端情况下每秒被调用 10-100 次。在 Fortran 中有许多方法可以测量时间,但由于调用的频率,我需要一种开销最低的方法。 时
我的电脑中的这段代码在java中执行了1秒,但在C中执行了20多秒。java是如何执行的? int a[] = new int[50000] ; for(int i = 0 ; i < 50000 ;
我用 fastai.tabular 训练了一个模型。现在,我有一个合适的学习器。最终,模型将应用于新数据,而不仅仅是在训练集上拟合并在测试集上进行评估等。我尝试了不同的方法,所有这些都导致了错误或一些
当我曾经对嵌入式系统和早期 8/16 位 PC(6502、68K、8086)进行编程时,我对每条指令执行所需的确切时间(以纳秒或微秒为单位)有很好的把握。根据系列的不同,一个(或四个)周期相当于一次“
让我立即澄清一下这个听起来很温和的标题。这实际上已经困扰我很长一段时间了,尽管感觉这是一个非常基本的问题。 许多语言让开发人员玩弄位,从而给人一种效率错误的印象,例如 bool.h据我了解,C hea
我有一个代码。 private static String generateString(int size) { StringBuffer s = new StringBuffer();
[简短回答:糟糕的基准测试方法。你会认为我现在已经想通了。] 问题表现为“找到一种快速计算 x^y 的方法,其中 x 和 y 是正整数”。典型的“快速”算法如下所示: public long fast
我必须乘以 2(大部分时间)稀疏矩阵。这些矩阵相当小(大约 10k*10k),我有两个至强四核和一个线程来完成这项工作? 是否有任何用于多线程 moltiplication 的快速库?还有其他建议吗?
我正在对约 40K 文档的集合执行 where in box 查询。查询耗时约 0.3 秒,获取文档耗时约 0.6 秒(结果集中约有 10K 文档)。 文档相当小(每个约 100 字节),我限制结果只
我正在寻找 4 个变量的标量函数的局部最小值,并且我对变量有范围约束(“框约束”)。函数导数没有封闭形式,因此需要解析导数函数的方法是不可能的。我已经用 optim 尝试了几个选项和控制参数功能,但所
我正在尝试部署一个使用 CGI::Application 的 Perl 应用程序通过 Nginx,它们之间使用 FastCGI 进行通信。 Nginx 不断返回“502 Bad Gateway”,错误
我对 C++ 很陌生,所以很抱歉,如果我问一些愚蠢的问题,但我在网上找不到答案(只有一篇引用 python ( Can mmap and gzip collaborate? ) 的帖子),试图看看是否
我正在试验不同类型的 OpenCV 的 FAST 检测器。 可用的类型有: TYPE_5_8, TYPE_7_12, TYPE_9_16 最后一个是默认的,用这张照片描述: 我假设 TYPE_7_12
我正在尝试开发一个 android 应用程序,它应该分析来自相机的帧并检测角落。 我的目标是检测当前棋盘状态并向服务器提供数据。 我已经在我的应用程序中实现了 OpenCV,并且正在尝试使用 FAST
我正在使用 Tensorflow 和 faster_rcnn_inception_v2_coco 模型训练对象检测器,但在对视频进行分类时遇到了很多误报。 经过一些研究,我发现我需要在训练过程中添加负
我是一名优秀的程序员,十分优秀!