Quote:
Originally Posted by Natsheh
Well then what do cause these unexpected behaviors?
|
I don't know what caused your particular error, it needs to be investigated. You didn't even post the line where this error occurs(debug would have shown that).
Quote:
Originally Posted by Natsheh
Also doesn't memory leak cause mem addresses to be overwritten?
|
No, a memory leak happens when memory is being allocated/reserved for use by a particular process and never freed. That memory is still owned by the process so no other process can get access to it. If the leaked block is big or if the leak happens often and the program runs for a long time, the leaks add up and may cause the system to run out of memory. At this point, things will stop working(when programs request memory the OS can not allocate any so the code will fail) or get slowed down significantly if swapping between ram and disk occurs.
You are probably thinking about something like a buffer overflow, where you attempt to write more data than a buffer can handle and without proper care, it may end up writing memory outside the allocated buffer, overwriting other areas of memory and potentially corrupting it or allowing attackers to exploit the application. There is a very common and basic example in C regarding a buffer overflow/index out of bounds(assume the compiler does not do any reordering when placing the variables on stack):
PHP Code:
int buf[5];
int a;
//on stack, if no reordering occurs, we have buf[0] buf[1] buf[2] buf[3] buf[4] a
a = 5;
buf[0] = 11;
buf[1] = 12;
buf[2] = 13;
buf[3] = 14;
buf[4] = 15;
//now memory holds 11 12 13 14 15 5
//5 is not a valid index inside buf, it is an attempt to write outside the buffer
//since a is allocated right after buf, writing to buf[5] will actually overwrite a
buf[5] = 100;
//now a is 100, not 5
//again, this is under the assumption that no reordering occurs and a is placed after buf. if a didn't exist and buf[5] address would land in a page that the process does not own(not yet allocated) the program would likely crash with a segmentation fault signal
__________________