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

(ITS#8487) Properly handle realloc() failures



Full_Name: Bryon Gloden, CISSP.
Version: 
OS: 
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (161.133.194.55)


Greetings. On line numbers 123 and 134 of liblmdb/midl.c
(https://github.com/LMDB/lmdb/blob/mdb.master/libraries/liblmdb/midl.c) there
are two common realloc() mistakes. Passing one pointer into realloc() and
assigning the result directly into that same pointer variable can cause a memory
leak if the reallocation fails, because the original allocation will still
exist. The correct way to do this is to use a temporary pointer variable.

Credit: http://stackoverflow.com/a/11548901

Found by https://github.com/bryongloden/cppcheck