This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc 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] _nss_nis_initgroups_dyn: Use struct scratch_buffer [BZ #18023]


On 06/25/2018 10:37 PM, DJ Delorie wrote:

fweimer@redhat.com (Florian Weimer) writes:
-      buf = extend_alloca (buf, buflen, 2 * buflen);
+      if (!scratch_buffer_grow (&tmpbuf))
+	return 1;

The docs say if _grow() fails, the buffer is still free'able.  Could we
not, or should we, use "break" here so that scratch_buffer_free() is
called when grow() fails?

The docs (scratch_buffer.h) mentions that the old buffer is freed, but
that the scratch_buffer is still "in a freeable state" so it's not clear
if the intention is that you *should* call scratch_buffer_free(), or
*must*, or *must not*, etc.

You can free the buffer again, but you don't have to. There is no memory leak if you don't.


      }
+ scratch_buffer_free (&tmpbuf);
    return 1;
  }

The point here is not call free if we know it is a no-op.

So I think the code is okay as-is.

+	if (!scratch_buffer_grow (&tmpbuf))
+	  {
+	    status = NSS_STATUS_TRYAGAIN;
+	    goto done;
+	  }

In this case, going to "done" *does* call scratch_buffer_free().  At
least we should be consistent within a given file ;-)

Here we call the entire cleanup sequence, which happens to include scratch_buffer_free as well, so the situation is different.

I hope this clarifies why things are the way they are.

Thanks,
Florian


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