From patchwork Thu Jul 21 19:38:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 651428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3rwPGv1LR3z9t0h for ; Fri, 22 Jul 2016 05:39:02 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=GPXBf6IV; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=NovFRzXWuQW8CJA5R+4p0ShbaHrV7R+RUENDdvDft4FTr2WyNpNkx IWg2sx/IKfGHkvfEWNljtpDahSSwkZgBvG004PtLhCh1Mrt87dkwAr8AcsIo/4Ed +ubpreonM1+wx6SGA6eOG73AAFyRpswCbqBZDff0qSh+bxW8PPkjsQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=hgYJ+eNpzTSUDPuLmdo7FP4B7ZE=; b=GPXBf6IVa7cUYrtebkrk /r19lgsGdR2aI86L5C0D+XjhN0xflDwv+ooErffZCrtEQY1vA8wKCA9TLE7b41fu UOpg8XIDseYIV7GiNaOJrPk0tOq6uoT8IkyKMawJFMR5eD78DTAnQ+LpnADChJfg uTvfyD8XABglWZosj86jVlc= Received: (qmail 39055 invoked by alias); 21 Jul 2016 19:38:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 39038 invoked by uid 89); 21 Jul 2016 19:38:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=revealed, classic, deliberately, 1039 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 21 Jul 2016 19:38:36 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3D4744BC3; Thu, 21 Jul 2016 19:38:35 +0000 (UTC) Received: from localhost (ovpn-116-61.ams2.redhat.com [10.36.116.61]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6LJcYOZ027731; Thu, 21 Jul 2016 15:38:35 -0400 Date: Thu, 21 Jul 2016 20:38:31 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 1/4] Fix undefined behaviour in libstdc++ testsuite Message-ID: <20160721193831.GF4264@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.6.2 (2016-07-01) I've finally got the testsuite able to run with ubsan and asan enabled, with a few hacks in place. That revealed quite a few problems! The first patch in this series just frees some memory which wasn't being deallocated. That isn't really a problem, as the tests exit immediately anyway, but it's nice to get clean reports from leak checkers. * testsuite/18_support/new_delete_placement.cc: Don't allocate (and leak) memory for arguments to placement delete. * testsuite/20_util/addressof/1.cc: Don't leak memory. * testsuite/22_locale/locale/global_locale_objects/3.cc: Likewise. * testsuite/23_containers/unordered_multimap/insert/55028-debug.cc: Likewise. Tested powerpc64-linux, committed to trunk. commit 45bf3919ae2dbf9223f10c4dd854a13fd2ebc7ee Author: Jonathan Wakely Date: Wed Jul 20 22:32:52 2016 +0100 Remove memory leaks in libstdc++ testsuite * testsuite/18_support/new_delete_placement.cc: Don't allocate (and leak) memory for arguments to placement delete. * testsuite/20_util/addressof/1.cc: Don't leak memory. * testsuite/22_locale/locale/global_locale_objects/3.cc: Likewise. * testsuite/23_containers/unordered_multimap/insert/55028-debug.cc: Likewise. diff --git a/libstdc++-v3/testsuite/18_support/new_delete_placement.cc b/libstdc++-v3/testsuite/18_support/new_delete_placement.cc index 2c4607b..9049dca 100644 --- a/libstdc++-v3/testsuite/18_support/new_delete_placement.cc +++ b/libstdc++-v3/testsuite/18_support/new_delete_placement.cc @@ -25,11 +25,11 @@ // libstdc++/7286 void test01() { - void* pc = new char; - void* pa = new char[10]; + char c = 'c'; + void* p = &c; void* tmp = 0; - operator delete(pc, tmp); - operator delete[](pa, tmp); + operator delete(p, tmp); + operator delete[](p, tmp); } int main() diff --git a/libstdc++-v3/testsuite/20_util/addressof/1.cc b/libstdc++-v3/testsuite/20_util/addressof/1.cc index 7208fc4..732eebc 100644 --- a/libstdc++-v3/testsuite/20_util/addressof/1.cc +++ b/libstdc++-v3/testsuite/20_util/addressof/1.cc @@ -41,6 +41,9 @@ void test01() VERIFY( std::addressof(o2) == ao2 ); VERIFY( std::addressof(f1) == &f1 ); + + delete ao1; + delete ao2; } int main() diff --git a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc index 0eb656c..ec33614 100644 --- a/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc +++ b/libstdc++-v3/testsuite/22_locale/locale/global_locale_objects/3.cc @@ -73,13 +73,15 @@ void test03() VERIFY( loc04 == global_orig ); } - // 2: Not destroyed when out of scope, deliberately leaked. + // 2: Not destroyed when out of scope, deliberately "leaked". + const facet_type* ptr = 0; { { { VERIFY( counter == 0 ); { - locale loc01(locale::classic(), new facet_type(1)); + ptr = new facet_type(1); + locale loc01(locale::classic(), ptr); VERIFY( counter == 1 ); global_orig = locale::global(loc01); name = loc01.name(); @@ -101,6 +103,9 @@ void test03() } VERIFY( counter == 1 ); + // Clean up. + delete ptr; + // Restore global settings. locale::global(global_orig); } diff --git a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc index 65830ad..e7afc8f 100644 --- a/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc +++ b/libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/55028-debug.cc @@ -30,7 +30,7 @@ void test() // using MyMap = std::multimap; // works using MyMap = std::unordered_multimap; // fails to link MyMap m; - m.insert(std::make_pair(std::string("blah"), new MyType)); + m.insert(std::make_pair(std::string("blah"), (MyType*)nullptr)); } int main()