This is the mail archive of the
mailing list for the glibc project.
Re: [PATCH] Initialize the entire obstack struct [BZ #17919]
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Siddhesh Poyarekar <siddhesh at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>, bug-gnulib at gnu dot org
- Date: Tue, 3 Feb 2015 07:38:06 -0800
- Subject: Re: [PATCH] Initialize the entire obstack struct [BZ #17919]
- Authentication-results: sourceware.org; auth=none
- References: <20150203145649 dot GG1528 at spoyarek dot pnq dot redhat dot com> <20150203150036 dot GH1528 at spoyarek dot pnq dot redhat dot com>
On Tue, Feb 3, 2015 at 7:00 AM, Siddhesh Poyarekar <email@example.com> wrote:
> ... and I forgot to add bug-gnulib to cc before I hit send.
> On Tue, Feb 03, 2015 at 08:26:49PM +0530, Siddhesh Poyarekar wrote:
>> 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== 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== 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== All heap blocks were freed -- no leaks are possible
>> ==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?
>> 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)
I think you should also remove
h->use_extra_arg = 0;