Q: possible memory leak in add_object() in io/ftw.c

Nardmann, Heiko heiko.nardmann@secunet.com
Fri Dec 2 08:32:00 GMT 2005


My lint tool has complained about the function add_object() in io/ftw.c:

static inline int
add_object (struct ftw_data *data, struct STAT *st)
{
  struct known_object *newp = malloc (sizeof (struct known_object));
  if (newp == NULL)
    return -1;
  newp->dev = st->st_dev;
  newp->ino = st->st_ino;
  return __tsearch (newp, &data->known_objects, object_compare) ? 0 : -1;
}

Here newp is allocated and given to __tsearch(). My problem is that I have not 
completely understood __tseach(). Two situations:

1) newp is a new entry. Then newp is entered into the tree and can be 
referenced via the tree root (and therefore free()d this way).

2) newp is no new entry. What happens then?

Any specialist for this code reading here?

-- 
Heiko Nardmann (Dipl.-Ing. Technische Informatik)
secunet Security Networks AG - Sicherheit in Netzwerken (www.secunet.de),
Weidenauer Str. 223-225, D-57076 Siegen
Tel. : +49 271 48950-13, Fax  : +49 271 48950-50
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20051202/738cb381/attachment.sig>


More information about the Libc-alpha mailing list