Heap Memory Errors and Stack Memory Errors
Page 1 of 1
Heap Memory Errors and Stack Memory Errors
Memory errors can be broadly classified into Heap Memory Errors and Stack Memory Errors.
Some of the challenging memory errors are:
-Invalid Memory Access in heap and stack
-Memory leak
-Mismatched Allocation/Deallocation
-Missing Allocation
-Uninitialized Memory Access in heap and stack
-Cross Stack Access
Invalid Memory Access
Memory Leak
Mismatch Allocation/ Deallocation
Missing Allocation
Uninitialized Memory Access
This problem happen on some of compiler only
Cross Stack Access
Some of the challenging memory errors are:
-Invalid Memory Access in heap and stack
-Memory leak
-Mismatched Allocation/Deallocation
-Missing Allocation
-Uninitialized Memory Access in heap and stack
-Cross Stack Access
Invalid Memory Access
- Code:
char *pStr = (char*) malloc(25);
free(pStr); //deallocated already
strcpy(pStr, .parallel programming.); // Invalid write to deallocated memory in heap
Memory Leak
- Code:
char *pStr = (char*) malloc(512);
//do not dellocate heap
return;
Mismatch Allocation/ Deallocation
- Code:
char *s = (char*) malloc(5);
delete s; // should deletes[] s;
Missing Allocation
- Code:
char* pStr = (char*) malloc(20);
free(pStr); // here deallocation already , no need 2 time
free(pStr); // results in an invalid deallocation
Uninitialized Memory Access
This problem happen on some of compiler only
- Code:
char *pStr = (char*) malloc(512);
char c = pStr[0]; // the contents of pStr were not initialized
- Code:
void func()
{
int a;
int b = a * 4; // uninitialized read of variable a
}
Cross Stack Access
- Code:
main()
{
int *p;
-------
CreateThread(., thread #1, .); // Stack Owned
CreateThread(., thread #2, .);
-------
}
Thread #1
{
int q[1024];
p = q;
q[0] = 1;
}
Thread #2
{
*p = 2; // Stack Cross Accessed
}
too wei- Sponsor
- Posts : 31
Points : 66331
Reputation : 0
Join date : 2015-04-21
Age : 25
Location : Johor
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|