Compartir a través de


PREfast Warning 308 (Windows CE 5.0)

Send Feedback

308 - Leaking memory.
Additional Information: If memory allocation fails, the pointer to allocated memory <pointer> will be clobbered by <function>'s return value of NULL.

This warning indicates a memory leak resulting from the incorrect use of a reallocation function.

Heap reallocation functions do not free the passed buffer if reallocation is unsuccessful, but PREfast has detected that the original pointer is overwritten with the result of the reallocation call.

Assign the result of the reallocation function to a temporary and then replace the original pointer after successful reallocation.

This warning can generate noise if there is a live alias to the buffer to be reallocated at the time of the assignment of the result of the reallocation function.

Example

Defective Source

char *x;

x = (char *)malloc(10);

if (x) {
    x = (char *)realloc(x,
                        512);
}

Corrected Source

char *x, *tmp;

x = (char *)malloc(10);

if (x) {
    tmp = (char *)realloc(x,
                          512);

    if (tmp != NULL) {
        x = tmp;
    }

    free(x);
}

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.