From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 41EFC3858D33 for ; Thu, 2 Mar 2023 07:32:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 41EFC3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-x12b.google.com with SMTP id j11so5239274lfg.13 for ; Wed, 01 Mar 2023 23:32:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677742375; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=cXorpIYh0XxzMkKWEbpdAtoq0n0w2tBUgBZKeeOFkXw=; b=lj5NyY6LZCElUxWtUWqKTEwZGbqXuU3PERT3kX2lDC+8w7q0PJYj3SuDJnEYWCYzcb 6U7OyS9RAmz/NTX72kg6jlOqKYpX+8TY+Mr186YH/kiTQePW7LKuZ8/X1covH7WX80a3 CzTCjiyJATowFVLP/8Kz2YuqGICykDjcNPTS7BKV66MwMYGK8+PIMGJl5ZaQBKSL8G6x NHP8TQjVX6hiIYaGRic0K5OChI3WbO1UNDp5qYsRMSO37NxsVMUhPaH0kRDM0ZYQW0ux TXb2A0PNqf9IivZnh5BE0tyeX6xTIBhyTQw1J+lBGquC5MOJVS72wY60fQUrcqP78I0R OYcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677742375; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=cXorpIYh0XxzMkKWEbpdAtoq0n0w2tBUgBZKeeOFkXw=; b=izUmVTLGsX0rASRXrYj6BfDA0dRkMmiHAHiS/IxJI9sRbosHTB8weq2kiEcg4ITqmz CuK3JE+eGOnLkdGtwnBErIqWdE7nLvp0G9+eQvp4G3Czq7gQQWaE2m2E+e+0u474f9fZ yZ5IhjdYipQo7uVdIQNB4reJ5qMa83AFTRwNGjXSeyq8h+XGSPlXMsgQ4O0kB2gV+ZRw WdpNqpZKrR8AQyGa1QX4/TPNpgi1x8AVVUe3dEc/vZ9CCpj5mUWxXvwcN4JiuAOWuBke uN4XpPxd06js7oPiQi6ucqCmXZEQ0/2S5LKk+P8BdgGstCQ+dLHipFKSlaMnnRac+Rf5 3m/w== X-Gm-Message-State: AO0yUKXh+VOQ7jff6ysDuF3vXr1vmlsRAGQx/CCy/RpKahGh4YJSgZBn 3rnADKueZC6e23KPywvlitB5Ex2zQPB/yyUr9cM= X-Google-Smtp-Source: AK7set9bk+FFSNiXNifrNCRj64fLX1/b54hJ9xtZjWHeR7BiQKfyHWS+qf6/Mt7YPWclc3GsR1+zVpI5U2cAx7r+u+E= X-Received: by 2002:ac2:51ba:0:b0:4db:1c2a:a96e with SMTP id f26-20020ac251ba000000b004db1c2aa96emr2694396lfk.9.1677742375334; Wed, 01 Mar 2023 23:32:55 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Thu, 2 Mar 2023 08:32:43 +0100 Message-ID: Subject: Re: [PATCH] libiberty: fix memory leak in pex-win32.c and refactor To: Costas Argyris Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: On Wed, Mar 1, 2023 at 7:14 PM Costas Argyris via Gcc-patches wrote: > > Hi > > It seems that the win32_spawn function in libiberty/pex-win32.c is leaking > the cmdline buffer in 2/3 exit scenarios (it is only free'd in 1/3). The > problem here is that the cleanup code is written 3 times, one at each exit > scenario. > > The proposed attached refactoring has the cleanup code appearing just once > and is executed for all exit scenarios, reducing the likelihood of such > leaks in the future. One could imagine that CreateProcess in case of success takes ownership of the buffer pointed to by cmdline? If you can confirm it is not then the patch looks OK to me. Thanks, Richard. > Thanks, > Costas