memory-corruption

glibc detected malloc(): memory corruption in C

瘦欲@ 提交于 2021-02-07 06:48:18
问题 I am trying to compile and code written in C under linux, and got this error message: glibc detected malloc(): memory corruption and I cannot find out why... the substring() just return you part of the original string by giving the starting index and length. e.g. substring("this is example",0,4) = "this"; char *substring(char* str, int start, int length) { char *newString = (char *)malloc(length * sizeof(char)); int i, x = 0; int end=start+length-1; for(i = start ; i <= end; i++){ newString[x

Passing an array of strings from C# to C++ DLL function and fill it in the DLL and get back

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:16:20
问题 I am writing a C# application that passes an empty string array of size 30 to a C++ DLL. This string array needs to be filled in the DLL and given back to the C# application. I my code I observe memory corruption at the end of function call from DLL. My C++ DLL code is as follows: SAMPLEDLL_API BOOL InitExecution (wchar_t **paszStrings, int count) { for (int i = 0 ; i < count; i++) { mbstowcs(*(paszStrings + i), "Good",4); //*(paszStrings + i) = "Good"; } return TRUE; } My C# code is string[]

Struggling - yet another memory corruption problem, bad alloc (C++, VS 2008)

独自空忆成欢 提交于 2019-12-24 18:16:47
问题 I've read a lot of posts on memory corruption and it seems like it can be a considerably difficult problem to solve. When I run my code on my linux machine it executes fine and valgrind doesn't report any leaks or errors. However when I run the code on my lab's windows machine with VS2008, I get a bad alloc error, stopping with _RAISE(nomem). This seems strange to me because I would have expected valgrind to catch it. void *__CRTDECL operator new(size_t size) _THROW1(_STD bad_alloc) { // try

glibc Heap Consistency Checking

若如初见. 提交于 2019-12-23 07:46:58
问题 According to posts from 2008 (I can't find it right now), glibc heap check doesn't work in multithreaded environment. Is it still situation now in 2010? Does heap check enabled by default? (gcc 4.1.2)? I don't set MALLOC_CHECK_, don't aware of calling mcheck(), but still sometimes receive double free glibc error with backtrace. Maybe it's enabled by some compilation flag? 回答1: By default, without using malloc_check_ or mcheck(), glibc does some little checks that doesn't hurt the performance,

Valgrind gives an error for nearly everything (Warning: client switching stacks?)

房东的猫 提交于 2019-12-22 01:27:02
问题 I'm corrupting memory somehow because my program crashes without error at random places. I'm using valgrind with --leak-check=full , compiling with -O0 -g , and the very first problem it detects is the first line in int main() cout << "reading file" << endl; with ==5089== Warning: client switching stacks? SP change: 0x7ff0004f8 --> 0x7feb7de10 ==5089== to suppress, use: --max-stackframe=4728552 or greater ==5089== Invalid write of size 8 ==5089== at 0x41E107: main (Dgn.cpp:2833) ==5089==

Why does this code corrupt memory?

扶醉桌前 提交于 2019-12-21 20:14:59
问题 This is a fairly newbie question which should be answerable reasonably quickly... Basically, after the first call to Printf in echo , the contents of args is corrupted. It sounds to me like i'm passing the pointers around incorrectly. But can't figure out why? #define MAX_PRINT_OUTPUT 4096 void Echo(char *args[MAX_COMMAND_ARGUMENTS], int argCount) { for (int i = 1; i < argCount; ++i) { Printf("%s ", args[i]); Printf("\n"); } }; void Printf(const char *output, ...) { va_list args; char

Why does this code corrupt memory?

守給你的承諾、 提交于 2019-12-21 20:14:22
问题 This is a fairly newbie question which should be answerable reasonably quickly... Basically, after the first call to Printf in echo , the contents of args is corrupted. It sounds to me like i'm passing the pointers around incorrectly. But can't figure out why? #define MAX_PRINT_OUTPUT 4096 void Echo(char *args[MAX_COMMAND_ARGUMENTS], int argCount) { for (int i = 1; i < argCount; ++i) { Printf("%s ", args[i]); Printf("\n"); } }; void Printf(const char *output, ...) { va_list args; char

Catching EngineExecutionException

左心房为你撑大大i 提交于 2019-12-21 17:51:47
问题 I have an application containing both managed and native code. The application currently has an unhandled exception filter, set via SetUnhandledExceptionFilter, which catches any critical errors, generates a minidump, records various application parameters, and exits the program. The unhandled exception handler does not catch an EngineExecutionException which occurs in the .NET runtime. We suspect the problem is memory corruption caused by the native portion of the application. The problem is

Having hard time tracking memory corruption - when running with Valgrind runs correctly with no errors

天大地大妈咪最大 提交于 2019-12-18 05:02:52
问题 We have a complex program that is working well on heavy duty input (any input actually) with no multithreading implemented. We've implemented multithreading with a threadpool, and given these input parameters I get these results: ( Note : Where I say no errors , it means I've tested with valgrind -v and when I say no memory leaks , it means I've tested it with valgrind --leak-check=full -v ). small_file: Runs successfully with more than 1 workers (threads), no valgrind errors, no memory leaks

TXMLDocument.Active := False causes FastMM4 errormessage “FastMM detected that a block has been modified after being freed”

半城伤御伤魂 提交于 2019-12-12 19:21:27
问题 we have a strange effect using Delphi XE8 with FastMM4 (Version 4.992) in FullDebugMode. To reproduce the effect, just create a new TForm application, put FastMM4 in the first line of the DPR file, put a Button on the Form and put the following code in the clickhandler: (You need to have FastMM 4 installed, FullDebugMode must be enabled in the FastMM4Options.inc file and the FullDebugMode.dll has to be in the output folder of your programm!) procedure TForm3.Button4Click(Sender: TObject); var