Re: [cc65] Need some help with a memory leak

From: Marc 'BlackJack Rintsch <marc1rintsch.de>
Date: 2010-05-04 22:22:57
On Tuesday 04 May 2010, Payton Byrd wrote:
> I'm stumped trying to track down a memory leak and I'm hoping someone
> here can spend a little time to help me out.  The only place in my
> app where I'm dynamically allocating memory is creating the linked
> list that holds the directory information for a drive, so I know it's
> gotta be in there somewhere.  However, I believe I've been very
> thorough in my cleanup code, but I could be wrong.
>
> All of the code for this bug can be found at these URLs:
>
> drives.h -
> http://cbmcommand.codeplex.com/SourceControl/changeset/view/43431#834
>475
> <http://cbmcommand.codeplex.com/SourceControl/changeset/view/43431#83
>4475>drives.c -
> http://cbmcommand.codeplex.com/SourceControl/changeset/view/43431#834
>476
>
> <http://cbmcommand.codeplex.com/SourceControl/changeset/view/43431#83
>4476>The problem appears in the getDirectory method.  This is the only
> place where memory is dynamically allocated and freed.  Help is
> GREATLY appreciated.

IMHO it's quite obvious in that first ``while`` construct.  Just grab 
pencil and paper and "step through" the code with two entries.

1. Current is the second one.  The loop body will be entered but the 
`next` pointer is null so the current pointer will be set to the first 
entry.
2. Now the loop body won't get executed because of the second condition: 
`prev` of the first entry is null.
3. The first entry will be freed after the loop.

The second entry is still allocated at this point.

Ciao,
	Marc 'BlackJack' Rintsch
-- 
“Programmers should be paid by the amount of code
 that they avoid writing.”  -- Michael P. Soulier

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue May 4 22:19:27 2010

This archive was generated by hypermail 2.1.8 : 2010-05-04 22:19:30 CEST