[LU-6541] potential memory leak in gssd_get_krb5_machine_cred_list Created: 29/Apr/15  Updated: 19/Jul/15  Resolved: 19/Jul/15

Status: Resolved
Project: Lustre
Component/s: None
Affects Version/s: None
Fix Version/s: Lustre 2.8.0

Type: Bug Priority: Minor
Reporter: Colin Ian King Assignee: Dmitry Eremin (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Environment:

Ubuntu 15.04


Severity: 1
Rank (Obsolete): 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)

{ retval = ENOMEM; goto out; }

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;
}



 Comments   
Comment by Gerrit Updater [ 19/Jul/15 ]

Oleg Drokin (oleg.drokin@intel.com) merged in patch http://review.whamcloud.com/14814/
Subject: LU-6541 utils: fix potential memory leaks with realloc()
Project: fs/lustre-release
Branch: master
Current Patch Set:
Commit: 55f2a237320f23cb59df23518f5a72698d4f251c

Comment by Peter Jones [ 19/Jul/15 ]

Landed for 2.8

Generated at Sat Feb 10 02:01:06 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.