DavidAlphaFox / memlink

Automatically exported from code.google.com/p/memlink
0 stars 1 forks source link

one mistake in function "mempool_create" #13

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. code review
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.
The second malloc should check mp->freemem is NULL pointer
--------------------------------------------------------------------------------
--------------
MemPool*    
mempool_create()
{
    MemPool *mp;

    mp = (MemPool*)zz_malloc(sizeof(MemPool));
    if (NULL == mp) {
        DERROR("malloc MemPool error!\n");
        return NULL;
    }
    memset(mp, 0, sizeof(MemPool));

    mp->size = MEMLINK_MEM_NUM;
    mp->freemem = (MemItem*)zz_malloc(sizeof(MemItem) * mp->size);
    if (NULL == mp) {       //---------should check mp->freemem is NULL pointer
        DERROR("malloc MemItem error!\n");
        zz_free(mp);
        return NULL;
    }
    memset(mp->freemem, 0, sizeof(MemItem) * mp->size);

    //g_mpool = mp;

    return mp;
}

Original issue reported on code.google.com by NexusOne...@gmail.com on 12 Jul 2011 at 3:48

GoogleCodeExporter commented 9 years ago
是的,确实有问题。

目前其实并不需要判断zz_malloc的返回值。

Original comment by zhaowei...@gmail.com on 14 Jul 2011 at 2:38