From patchwork Thu Aug 31 13:02:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 808234 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-83915-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="DSFHuHVx"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xjjFw6f0cz9sMN for ; Thu, 31 Aug 2017 23:02:28 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; q=dns; s=default; b= caOiPajcvokS+PZFNq5wqotXUe5HstysEGQWGcqAQTLHq0jLtGF9iR8LaH2N29sl atEyhhT52I6Hh1nitWvbfR+T9BhcVuup3osFel+/ab2BzsnXhgEEvH83YaYXCGHn J9trXTth88V/BPnG/lLTXTMud4qooCiLPKV9g8KduaU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:to:subject:mime-version:content-type :content-transfer-encoding:message-id:from; s=default; bh=oxbw5E BC1CpDbBKrwv0odaROpVc=; b=DSFHuHVxPYarqXSzqYyawt5P1I8opfHG6M2pvo s3q1QP7Sa3+7BAc7AnVmRk1qHjIgeUJagYuczxpv9TLjJxSiSi0/Cja6HYyDkePe K0ZVay5w6D73vPN7DuoSUpRWfIBHM+JhQ/foEEWnXjv9WlCrmvkNQHzRMF2P2wKu qvQgs= Received: (qmail 31360 invoked by alias); 31 Aug 2017 13:02:23 -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 30139 invoked by uid 89); 31 Aug 2017 13:02:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=hurt X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8A14491FEA Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=fweimer@redhat.com Date: Thu, 31 Aug 2017 15:02:10 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] malloc: Resolve compilation failure in NDEBUG mode User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170831130210.9520943994318@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) In _int_free, the locked variable is not used if NDEBUG is defined. 2017-08-31 Florian Weimer * malloc/malloc.c (_int_free): Remove locked variable and related asserts. diff --git a/malloc/malloc.c b/malloc/malloc.c index 768670ccf6..e1159a5bce 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -4106,8 +4106,6 @@ _int_free (mstate av, mchunkptr p, int have_lock) mchunkptr bck; /* misc temp for linking */ mchunkptr fwd; /* misc temp for linking */ - int locked = 0; - size = chunksize (p); /* Little security check which won't hurt performance: the @@ -4162,19 +4160,14 @@ _int_free (mstate av, mchunkptr p, int have_lock) /* We might not have a lock at this point and concurrent modifications of system_mem might have let to a false positive. Redo the test after getting the lock. */ - if (have_lock - || ({ assert (locked == 0); - __libc_lock_lock (av->mutex); - locked = 1; + if (!have_lock + || ({ __libc_lock_lock (av->mutex); chunksize_nomask (chunk_at_offset (p, size)) <= 2 * SIZE_SZ - || chunksize (chunk_at_offset (p, size)) >= av->system_mem; - })) + || chunksize (chunk_at_offset (p, size)) >= av->system_mem; + })) malloc_printerr ("free(): invalid next size (fast)"); if (! have_lock) - { - __libc_lock_unlock (av->mutex); - locked = 0; - } + __libc_lock_unlock (av->mutex); } free_perturb (chunk2mem(p), size - 2 * SIZE_SZ); @@ -4211,10 +4204,8 @@ _int_free (mstate av, mchunkptr p, int have_lock) */ else if (!chunk_is_mmapped(p)) { - if (! have_lock) { + if (!have_lock) __libc_lock_lock (av->mutex); - locked = 1; - } nextchunk = chunk_at_offset(p, size); @@ -4328,10 +4319,8 @@ _int_free (mstate av, mchunkptr p, int have_lock) } } - if (! have_lock) { - assert (locked); + if (!have_lock) __libc_lock_unlock (av->mutex); - } } /* If the chunk was allocated via mmap, release via munmap().