heap-corruption

Heap corruption in C

和自甴很熟 提交于 2021-02-19 05:10:06
问题 int main () { int * b; b = (int*) malloc (1); *b=110000; free (b); return 0; } Why does heap corruption happen at free (b); ? IMO, heap corruption already happens at *b=110000; . 回答1: malloc() 's argument is the number of bytes to allocate. You need to use: b = (int*) malloc(sizeof(int)); You've allocated too small a block, and then written more bytes to it than you've allocated, which overwrites bookkeeping information next to the block, corrupting the heap. 回答2: It is at *b=110000; Because

Heap corruption in C

倖福魔咒の 提交于 2021-02-19 05:10:02
问题 int main () { int * b; b = (int*) malloc (1); *b=110000; free (b); return 0; } Why does heap corruption happen at free (b); ? IMO, heap corruption already happens at *b=110000; . 回答1: malloc() 's argument is the number of bytes to allocate. You need to use: b = (int*) malloc(sizeof(int)); You've allocated too small a block, and then written more bytes to it than you've allocated, which overwrites bookkeeping information next to the block, corrupting the heap. 回答2: It is at *b=110000; Because

array wrapper corrupts stack

有些话、适合烂在心里 提交于 2020-06-29 03:48:31
问题 my project is a dynamic array wrapper like std::vector. this is how it works: when adding a new element, the memory is either allocated (malloc), if it is 0, or reallocated with a new size (realloc), if it is not 0. the size is the number of elements * size of type when getting an already added element, i calculate the address by multiplying its index by the size of the type and adding it to the address at which the memory is allocated NOTE: i write and read the memory myself with no function

What is the difference between glibc's MALLOC_CHECK_, M_CHECK_ACTION, and mcheck?

元气小坏坏 提交于 2020-05-12 14:06:35
问题 glibc seems to have more than one way of doing some heap checking: mallopt with the M_CHECK_ACTION parameter the MALLOC_CHECK_ environment variable the mcheck family of functions I find the available documentation to be confusing. The manual doesn't list M_CHECK_ACTION at all when describing mallopt. This mallopt man page, however, does describe M_CHECK_ACTION. Additionally, it says it's equivalent to the environment variable MALLOC_CHECK_: MALLOC_CHECK_ This environment variable controls the

delete array pointers heap corruption

一笑奈何 提交于 2020-04-21 05:25:47
问题 I get an exception on this line in Visual Studio 2015. It builds with no errors. _free_dbg(block, _UNKNOWN_BLOCK); This is how I declare the new array of pointers: CAirship * pAirShip[10]; This is how I delete the array of pAirShip pointers: for (int i = 0; i < 10; i++) { if (pAirShip[i]) { cout << "pAirShip[" << i << "] is " << pAirShip[i] << endl; delete pAirShip[i];// Delete appropriate object } } // end for loop I get an error on attempting to delete pAirShip[0] , Here is a debug window

delete array pointers heap corruption

北战南征 提交于 2020-04-21 05:25:11
问题 I get an exception on this line in Visual Studio 2015. It builds with no errors. _free_dbg(block, _UNKNOWN_BLOCK); This is how I declare the new array of pointers: CAirship * pAirShip[10]; This is how I delete the array of pAirShip pointers: for (int i = 0; i < 10; i++) { if (pAirShip[i]) { cout << "pAirShip[" << i << "] is " << pAirShip[i] << endl; delete pAirShip[i];// Delete appropriate object } } // end for loop I get an error on attempting to delete pAirShip[0] , Here is a debug window

delete array pointers heap corruption

本秂侑毒 提交于 2020-04-21 05:23:51
问题 I get an exception on this line in Visual Studio 2015. It builds with no errors. _free_dbg(block, _UNKNOWN_BLOCK); This is how I declare the new array of pointers: CAirship * pAirShip[10]; This is how I delete the array of pAirShip pointers: for (int i = 0; i < 10; i++) { if (pAirShip[i]) { cout << "pAirShip[" << i << "] is " << pAirShip[i] << endl; delete pAirShip[i];// Delete appropriate object } } // end for loop I get an error on attempting to delete pAirShip[0] , Here is a debug window