This is the mail archive of the cygwin-patches@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] pwdgrp::read_group(): Don't call free() twice with the same address


On Sun, Aug 17, 2003 at 10:50:58AM -0400, Pierre A. Humblet wrote:
>While Dave Rothenberger has correctly localized the problem
>described in
><http://www.cygwin.com/ml/cygwin/2003-08/msg00364.html>
>the patch 
><http://cygwin.com/ml/cygwin-patches/2003-q3/msg00062.html>
>only fixes the symptom of the bug but not the root cause.
>
>Setting gr_mem to &null_ptr below should not be necessary
>because the subsequent load() should reset curr_lines to 0
>and call pwdgrp::parse_group (), which sets gr_mem to &null_ptr.
>Thus free() should never be called twice. 
>******
>  for (int i = 0; i < gr.curr_lines; i++)
>    if ((*group_buf)[i].gr_mem != &null_ptr)
>      {
>        free ((*group_buf)[i].gr_mem);
>        (*group_buf)[i].gr_mem = &null_ptr;
>      }
>
>  load ("/etc/group");
>******
>
>The original bug report mentions that the problem only occurs 
>when /etc is absent. In that case curr_lines is NOT reset by 
>pwdgrp::load, although it is incremented when the default entries
>(the ones with "mkpasswd" and "????????") are added to the internal 
>group file. 
>When /etc does not exist, the default entries are added repeatedly 
>and the internal group file keeps growing (ditto for passwd).
>
>I believe that reverting the original patch and applying the one 
>below fixes the root bug.

You're absolutely right.  Please check in.

cgf


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]