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.

Join the forum, it's quick and easy

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.
Evo. G Tech Team Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Heap Memory Errors and Stack Memory Errors

Go down

Heap Memory Errors and Stack Memory Errors Empty Heap Memory Errors and Stack Memory Errors

Post by too wei 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 : 66331
Reputation : 0
Join date : 2015-04-21
Age : 25
Location : Johor

Back to top Go down

Back to top


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