Test case 11

Memory leakage - case 1: a (simple) memory leak test case. See the following code snippet:

static const size_t BLK_1MB = 1024*1024;[...]static void amleaky(size_t mem){    char *ptr;    ptr = malloc(mem);    if (!ptr)        FATAL("malloc(%zu) failed\n", mem);    /* Do something with the memory region; else, the compiler     * might just optimize the whole thing away!     * ... and we won't 'see' the leak.     */    memset(ptr, 0, mem);    /* Bug: no free, leakage */}[...]/* test case 11 : memory leak test case 1: simple leak */static void leakage_case1(size_t size){ printf("%s(): will now leak %zu bytes (%ld MB)\n",     __FUNCTION__, size, size/(1024*1024)); amleaky(size);}[...] case 11:     leakage_case1(32);     leakage_case1(BLK_1MB);     break;[...]

As one can clearly see, ...

Get Hands-On System Programming with Linux now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.