[PATCH] Initialize the entire obstack struct [BZ #17919]

Siddhesh Poyarekar siddhesh@redhat.com
Tue Feb 3 14:56:00 GMT 2015


Hi,

obstack_init does not completely initialize the obstack structure; it
leaves out the padding bits and valgrind complains about it on s390x:

==15793== Memcheck, a memory error detector
==15793== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==15793== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==15793== Command: /root/obstack
==15793==
==15793== Conditional jump or move depends on uninitialised value(s)
==15793==    at 0x403E48CA4E: obstack_free (in /lib64/libc-2.12.so)
==15793==    by 0x8000072D: main (obstack.c:12)
==15793==
==15793==
==15793== HEAP SUMMARY:
==15793==     in use at exit: 0 bytes in 0 blocks
==15793==   total heap usage: 1 allocs, 1 frees, 4,064 bytes allocated
==15793==
==15793== All heap blocks were freed -- no leaks are possible
==15793==
==15793== For counts of detected and suppressed errors, rerun with: -v
==15793== Use --track-origins=yes to see where uninitialised values come from
==15793== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)


The fix below (against gnulib, but is identical for glibc) initializes
all of the obstack struct at once.  Verified that the valgrind warning
is fixed.  OK for 2.22 and gnulib?

Siddhesh

ChangeLog for gnulib:

	obstack: Initialize whole obstack structure.
	* lib/obstack.c (_obstack_begin): Initialize all of H.

ChangeLog for glibc:

	[BZ #17919]
	* malloc/obstack.c (_obstack_begin): Initialize all of H.

diff --git a/malloc/obstack.c b/malloc/obstack.c
index 5bb3f0d..c1d6ded 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -148,6 +148,8 @@ _obstack_begin (struct obstack *h,
 {
   struct _obstack_chunk *chunk; /* points to new chunk */
 
+  memset (h, 0, sizeof (struct obstack));
+
   if (alignment == 0)
     alignment = DEFAULT_ALIGNMENT;
   if (size == 0)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20150203/3a875c84/attachment.sig>


More information about the Libc-alpha mailing list