From patchwork Tue Feb 3 14:56:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 4898 Received: (qmail 30672 invoked by alias); 3 Feb 2015 14:56:57 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 30663 invoked by uid 89); 3 Feb 2015 14:56:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Tue, 3 Feb 2015 20:26:49 +0530 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH] Initialize the entire obstack struct [BZ #17919] Message-ID: <20150203145649.GG1528@spoyarek.pnq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) 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)