Permalink
Browse files

malloc add protection

  • Loading branch information...
1 parent 4c0d4ea commit 7a7d82cbba0ce069e35da5ede2ca7615b764055d @Yemsheng committed Oct 21, 2012
Showing with 12 additions and 0 deletions.
  1. +12 −0 BuddyMem.cpp
View
@@ -71,6 +71,14 @@ void BuddyMem::BuddyMemDestroy()
char* BuddyMem::BuddyMemMalloc(const unsigned int size)
{
+ if(!m_createFlag)
+ {
+ return NULL;
+ }
+ if(size == 0)
+ {
+ return NULL;
+ }
unsigned int needBlockAmount = size/m_blockSize;
if(size%m_blockSize!=0)
{
@@ -132,6 +140,10 @@ char* BuddyMem::BuddyMemMalloc(const unsigned int size)
void BuddyMem::BuddyMemFree(char *pMem)
{
+ if(!m_createFlag)
+ {
+ return;
+ }
unsigned int index = 0;
LinkNode *nodeFind = NULL;
LinkNode *nodePre = NULL;

0 comments on commit 7a7d82c

Please sign in to comment.