简体   繁体   English

C-运行时错误,`malloc(sizeof(int))`导致程序崩溃

[英]C - runtime error, `malloc(sizeof(int))` causing program to crash

Here is a piece of code: 这是一段代码:

int* linenump;
// ... other stuff
printf("----\n");
linenump = malloc(sizeof(int));
printf("*****\n");

The program only print out ---- then stopped, pop up a window says that the program has stopped, I paste the code in VS then build&run it, no errors, the program works fine. 该程序只打印出----然后停止,弹出一个窗口,说该程序已经停止,我将代码粘贴到VS中,然后生成并运行它,没有错误,程序运行正常。

It's a console application. 这是一个控制台应用程序。

So, what I want to know is, in what situation that this will happen? 所以,我想知道的是,在什么情况下会发生这种情况? and how should I solve it? 以及如何解决?

Thanks in advance. 提前致谢。


EDIT: 编辑:
here is the full source code: 这是完整的源代码: urldown urldown

You probably have some heap corruption somewhere earlier in the program but this is not showing up until this point. 您可能在程序的较早位置出现了一些堆损坏,但这直到现在都没有出现。 Run your code under valgrind to identify the real problem. valgrind下运行代码以找出真正的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM