From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6B4783858C5E for ; Mon, 3 Apr 2023 22:12:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6B4783858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680559975; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:content-type:content-type; bh=UdG40OWxqUkIyfHJcBOejgewIhDI8cS3yf8fBIyb5is=; b=aWo57kX12hgQvzUSEAUi0AXYENUBvus0NTpcKG2Yc8dVdaGjAXKOUe/CzYMfTrU09bnaEb BJGry2gUANqmZ4JGc/HvuzWj9J8XO5fcORZZRgyx9uaW5Fqk0UUJt6M+riOXhruHWzjoe4 kjvJeGHGd864ZyEJYAZl5urrpb7gWlw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-524-5l2qCwbLPmqsM1Bvu0f53w-1; Mon, 03 Apr 2023 18:12:53 -0400 X-MC-Unique: 5l2qCwbLPmqsM1Bvu0f53w-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9F32B800B23 for ; Mon, 3 Apr 2023 22:12:53 +0000 (UTC) Received: from greed.delorie.com (unknown [10.22.8.104]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8AC70175AD for ; Mon, 3 Apr 2023 22:12:53 +0000 (UTC) Received: from greed.delorie.com.redhat.com (localhost [127.0.0.1]) by greed.delorie.com (8.15.2/8.15.2) with ESMTP id 333MCqo12032375 for ; Mon, 3 Apr 2023 18:12:53 -0400 Date: Mon, 03 Apr 2023 18:12:52 -0400 Message-Id: From: DJ Delorie To: libc-alpha@sourceware.org Subject: [patch v1] malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: >From 61bd502ecac4d63f04c74bfc491ca675660d26b7 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Mon, 3 Apr 2023 17:33:03 -0400 Subject: malloc: set NON_MAIN_ARENA flag for reclaimed memalign chunk (BZ #30101) Based on these comments in malloc.c: size field is or'ed with NON_MAIN_ARENA if the chunk was obtained from a non-main arena. This is only set immediately before handing the chunk to the user, if necessary. The NON_MAIN_ARENA flag is never set for unsorted chunks, so it does not have to be taken into account in size comparisons. When we pull a chunk off the unsorted list (or any list) we need to make sure that flag is set properly before returning the chunk. diff --git a/malloc/malloc.c b/malloc/malloc.c index 0315ac5d16..66e7ca57dd 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -5147,6 +5147,8 @@ _int_memalign (mstate av, size_t alignment, size_t bytes) p = victim; m = chunk2mem (p); set_inuse (p); + if (av != &main_arena) + set_non_main_arena (p); } else {