Subject: Memory Leaks

From: "Eric L. Schott" <[email-masked]>
Date: Thu, 20 Nov 1997 10:05:58 -0500 (EST)

I was looking at the code for fvwm/windows.c.  I see a loop which
calls "GetToken."  From the comments with GetToken:

  ** GetToken: destructively rips next token from string, returning it
  **           (you should free returned string later)

I do not see a "free(tok)" in windows.c.  Should this be added? 

Also in windows.c, I see a call to strdup.  I have never used this
service, but it seems from the man page that free needs to be called
here too.  Diffs are below.

(I am not on this group; please respond by email.)

Eric

+--------------------------------------------------------------------------+
|   Eric L. Schott  <[email-masked]>     "And when you get lost in        |
|   The Pennsylvania State University      life, know that the road of     |
|   Office: (814) 863-4194                 return to God is always open."  |
|   Fax     (814) 863-7841                             Albert Schweitzer,  |
|   http://www.personal.psu.edu/els6                 Letter to god-child.  |
+--------------------------------------------------------------------------+

*** windows.c.dist	Tue Nov 11 08:50:56 1997
--- windows.c	Thu Nov 20 09:31:10 1997
***************
*** 143,149 ****
--- 143,152 ----
        {
          fvwm_msg(ERR,"WindowList","Unknown option '%s'",tok);
        }
+ 
+       free (tok);
      }
+     free(line);
    }
  
    globalFlags = flags;

--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: "Charles Hines" <[email-masked]>
Date: Thu, 20 Nov 1997 14:28:40 -0500

>>>>> "Eric" == Eric L Schott <[email-masked]> writes:

Eric> I was looking at the code for fvwm/windows.c.  I see a loop which
Eric> calls "GetToken."  From the comments with GetToken:

Eric>   ** GetToken: destructively rips next token from string, returning it
Eric>   **           (you should free returned string later)

Eric> I do not see a "free(tok)" in windows.c.  Should this be added?

Yup.  Thanks for catching that.  Prompted me to take a quick look & I
found a couple of other places where this was happening too...

Eric> Also in windows.c, I see a call to strdup.  I have never used this
Eric> service, but it seems from the man page that free needs to be called
Eric> here too.

That's true, but probably not needed in this case.  GetToken eats away
at that strdup'ed string until there is nothing left (freeing as it
goes) so it should be completely freed by the time it exist the while
loop.  I can put a check in anyways though, just to be safe.

Chuck