From patchwork Fri Jun 20 10:43:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 362151 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 E2A60140088 for ; Fri, 20 Jun 2014 20:43:30 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=dBN/4eutJK/GUCXPqir0pBq1NwlCn NHssyr7LVGJ9FNBEfQ1gm+Lu9gbAgnQgegDvgUXTN+rr2S4uVM4uq+iHCp9tvm7A NfPY9/ONP6nQ6lTDKFLPyR3RH7tQelujYv65eAV63AYdx+2Le97Dc7XHNGoQ/san yzDNrBjlqLSuPw= 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:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=ugZBM+NDBqnZvhWPhLSP+O5q2F4=; b=NA8 ctHu58T47dsxAMNqlQOQVy/RmRbWKSIgb5FLHHclMJMmikGzgiWglvdK+r9SjaGz lZfm7GAk4aAWOA4l73qBSqGm1uwdoK1Fk8HESVH6fH43FM6KRhALL963E0FVkHK3 v+LfrzBNZeN8b18JXc6LfLkJ9g6gv4RJXCDboZdM= Received: (qmail 29393 invoked by alias); 20 Jun 2014 10:43:25 -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 29378 invoked by uid 89); 20 Jun 2014 10:43:25 -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, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: mail-out.m-online.net X-Auth-Info: Gb4GpGc7fExx9BlSqs+LDPHVrd6baMjqcT7XP4l5hBw= From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Fix another memory leak in regexp compiler (BZ #17069) X-Yow: Where's my SOCIAL WORKER? Date: Fri, 20 Jun 2014 12:43:18 +0200 Message-ID: <87y4wrn9o9.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.91 (gnu/linux) MIME-Version: 1.0 [BZ #17069] * posix/regcomp.c (parse_reg_exp): Deallocate partially constructed tree before returning error. * posix/bug-regexp36.c: Expand test case. diff --git a/posix/bug-regex36.c b/posix/bug-regex36.c index 3dda026..59e2b6d 100644 --- a/posix/bug-regex36.c +++ b/posix/bug-regex36.c @@ -1,4 +1,4 @@ -/* Test regcomp not leaking memory on invalid repetition operator +/* Test regcomp not leaking memory on parse errors Copyright (C) 2014 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -24,6 +24,6 @@ main (int argc, char **argv) { regex_t r; mtrace (); - regcomp (&r, "[a]\\{-2,}", 0); + regcomp (&r, "[a]\\|[a]\\{-2,}", 0); regfree (&r); } diff --git a/posix/regcomp.c b/posix/regcomp.c index a5020be..076eca3 100644 --- a/posix/regcomp.c +++ b/posix/regcomp.c @@ -2154,7 +2154,11 @@ parse_reg_exp (re_string_t *regexp, regex_t *preg, re_token_t *token, { branch = parse_branch (regexp, preg, token, syntax, nest, err); if (BE (*err != REG_NOERROR && branch == NULL, 0)) - return NULL; + { + if (tree != NULL) + postorder (tree, free_tree, NULL); + return NULL; + } } else branch = NULL;