questions on idmap_tdb.c

simo idra at samba.org
Thu Feb 22 21:13:54 GMT 2007


On Thu, 2007-02-22 at 11:45 -0800, Herb Lewis wrote:
> Trying to understand what these functions do I was looking at
> idmap_tdb_remove_mapping and have some questions. First it
> seems like we have a memory leak on data.dptr. We have the
> following 2 lines midway through the function
> 
>          /* Check if sid is present in database */
>          data = tdb_fetch(ctx->tdb, ksid);
> 
> If I followed the code correctly, data.dptr is malloced in
> the tdb_fetch function. However between these 2 lines and
> the following lines there was no SAFE_FREE like follows
> all the remaining calls to tdb_fetch
> 
>          /* Delete previous mappings. */
> 
>          data = tdb_fetch(ctx->tdb, ksid);
> 
> We already know data.dptr is nonzero (or we would have
> skipped this code) so it seems a simple SAFE_FREE(data.dptr);
> before the next fetch is required or we leak that memory.
> The other option would be to just remove the tdb_fetch
> for ksid as that is what the previous tdb_fetch got.
> I'm not sure if there was a reason for doing the fetch
> again.

Removing the second fetch, it must have been a copy&paste error, thanks
for spotting this.

> Second question is we do we need to do the fetch if we are
> going to be calling tdb_delete? We do this before the
> delete of both ksid and kid.

Just removing both the fetches, make no sense indeed :-)

Simo.

-- 
Simo Sorce
Samba Team GPL Compliance Officer
email: idra at samba.org
http://samba.org



More information about the samba-technical mailing list