Details
-
Bug
-
Resolution: Fixed
-
Minor
-
None
-
None
-
Ubuntu 15.04
-
1
-
9223372036854775807
Description
static analysis by cppcheck has found a potential memory leak in gssd_get_krb5_machine_cred_list():
[lustre/utils/gss/krb5_util.c:918]: (error) Common realloc mistake: 'l' nulled but not freed upon failure
listsize += listinc;
l = (char **)
realloc(l, listsize * sizeof(char *));
if (l == NULL)
The semantics of realloc are to return NULL when the allocation fails, but won't free the original allocation:
"The realloc() function returns a pointer to the newly allocated memory,
which is suitably aligned for any built-in type and may be different
from ptr, or NULL if the request fails. If size was equal to 0, either
NULL or a pointer suitable to be passed to free() is returned. If
realloc() fails, the original block is left untouched; it is not freed
or moved."
so, one needs to do something like:
tmp = (char **)realloc(l, listsize * sizeof(char *));
if (tmp)
l = tmp;
else {
retval = ENOMEM;
goto out;
}