Deallocating memory in isc code.

kalpesh varyani at
Wed Jun 8 13:19:07 UTC 2011


Is it necessary to deallocate memory assigned using isc_mem_get() by
explicitly using isc_mem_free()?

Ref: File builtin.c is available at*builtin*.*c*<>

Following is the code snippet:

static isc_result_t builtin_create(const char *zone, int argc, char
**argv,void *driverdata, void **dbdata)
builtin_t *empty; <-- Local variable.
empty = *isc_mem_get*(ns_g_mctx, sizeof(*empty)); <-- Memory assigned using
server = isc_mem_strdup(ns_g_mctx, argv[1]);
contact = isc_mem_strdup(ns_g_mctx, argv[2]);
if (empty == NULL || server == NULL || contact == NULL) {
    *dbdata = &empty_builtin;
    if (server != NULL)
        isc_mem_free(ns_g_mctx, server);
    if (contact != NULL)
        isc_mem_free(ns_g_mctx, contact);
    if (empty != NULL)
        isc_mem_put(ns_g_mctx, empty, sizeof (*empty));

Here memory is assigned using isc_mem_get() however isc_mem_free() is
conditional. Thus if conditions are false then there will be no

1. Even if *builtin_t *empty; *is local to the function *builtin_create*, can
it cause memory leak?
2. what should be the rerurn value of *isc_mem_strdup()* on success/failure?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the bind-users mailing list