Evo. G Tech Team Forum
Welcome to Evo. G Tech Team Forum. We have moved to a new website : www.evogtechteam.com

Thanks you.

by Evo. G Tech Team Management.

Heap Memory Errors and Stack Memory Errors

View previous topic View next topic Go down

Heap Memory Errors and Stack Memory Errors

Post by too wei on September 10th 2015, 22:13

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
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
Sponsor

Posts : 31
Points : 17811
Reputation : 0
Join date : 2015-04-21
Age : 19
Location : Johor

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum