[Date Prev][Date Next] [Chronological] [Thread] [Top]

(ITS#4477) Realloc memory leak during temporary memory shortage

Full_Name: Sean Burford
Version: 2.3.20
OS: Linux
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (

When realloc(ptr, size) fails, ptr is still valid.  When used like this:
  ptr = realloc(ptr, size)
the original valid ptr is discarded if realloc fails.  This causes a memory leak
when there is a temporary memory shortage.  This was previously discussed, in
different circumstances, in issue 2126.

I'm looking into malloc/realloc fails we seem to be experiencing during
value_add() for  modifications of large groups (servers/slapd/value.c).  the
realloc in value_add() will leak memory as described above.  A temporary
variable should be used to check the return value of realloc.

I have verified this in CVS openldap HEAD.

A quick grep reveals v2ref() in servers/slapd/result.c uses the same poor form
of realloc.