开发者

glibc detected memory corruption

I have the following function.

129 string cmdline::compile_sOpt(const cl_开发者_StackOverflowoption *options)
130 {
131    assert(options != MEM0x0);
132 
133    string sOpt;
134    int i =0;
135    while(options[i].lo_name != MEM0x0){
136       sOpt += options[i].so_name;
137       if(options[i].has_arg == required_argument ||
138          options[i].has_arg == optional_argument)
139             sOpt += GC_GETOPT_ARG;
140       ++i;
141    }
142 
143    return sOpt;
144 }

The following error occurs in the return of this function.

*** glibc detected *** ./a.out: malloc(): memory corruption: 0x000000000133c1a0 ***

I have commented out all of the code and written the following and the error still persists.

string s;
return s;

so_name and GC_GETOPT_ARG are both const char. In gdb sOpt never holds a value.

Thanks in advance.

EDIT: Thanks for the pointers. I figured out the error and I am ashamed to say that I made it. But the error was memset off the end of an array.


You've probably trashed the stack or heap. The error would suggest it's more likely to be the heap, but there's no guarantee stack corruption isn't the cause. The corruption is occurring prior to this function being called.

Update0

memset off the end of an array

Is a classic case of corruption that would cause this, I'd suspect you've done this to a region in the heap which has corrupted it. The next call to malloc or free will cause the program to terminate when the problem is detected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜