From patchwork Thu Oct 21 03:39:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573687 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD235C433F5 for ; Thu, 21 Oct 2021 03:39:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8E31760E8C for ; Thu, 21 Oct 2021 03:39:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230103AbhJUDmF (ORCPT ); Wed, 20 Oct 2021 23:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbhJUDmE (ORCPT ); Wed, 20 Oct 2021 23:42:04 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04753C06161C for ; Wed, 20 Oct 2021 20:39:49 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id z69so24114172iof.9 for ; Wed, 20 Oct 2021 20:39:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=XBhPzETMNSo70eaqyYiIaSZIT7Nf4nlhyp+Bstz0o+4=; b=kAqo3mHS/HUn7FfuQldeinWQSW3PhL7GIoNmQsAwe/3X0Tg8+mItXDIw1L3gyhS8NO jlnQTLl8k+Z9fOnrhzOrvbGRpegodLXchCznaF6BTExfRRWp5inD0pvlk2/uXu2TNgdR 75toFw2weTDEvngt9qrTzab2Csf5qNPRRCNbaBtFObcMXyyCRlc5EVQKrIwHTI6m1TGU WGXREkCRkm7E5C+9TvP4cO4AOV4pVX+iBUdTlZ6ObXovneK04xeZranNNKiPi9OzPvJg ca7W1CbX4eLI3bj+24UpxhV8v2WaHdU2FTOA+uyHMiPn9lYdAE7/SPvi6kJVdedn0izv qTcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=XBhPzETMNSo70eaqyYiIaSZIT7Nf4nlhyp+Bstz0o+4=; b=eBPAZlOrRc483hbNcuAdb50jfCWNVwMlEI+eEpy+5FH7jKYJDSejfx5NfxmbFZP1MM rwf3w/nyROFVYDz8iio9VPZEIewf05bJ1KMpzqjtAUwlEpsMyZlUr4Jc/zxn307Z7jkX bJQveLBAkgiX6AQ3LMie3QkGyTNwJEC2yghX6SXyhT6qCP2B2k5cd2ZINJSshGnHBQgT eiY1Z7eFRQQpDzFJ1TrlfPRerKUq7BeUxMbsMRVKW3doEenBfI8Ai85HyY/vtJ0Canwj yIIuWB2PuDWFTL7YVHOKFK4I5FrBagPqpAb0tpmmzqMaHhFfT3xXhK4hoDfwsYR2KgO/ ZL/w== X-Gm-Message-State: AOAM532estaObyhXYpTB9+MaWW0nsjCa1Rf1Xx43MVynqjtH5ZRBNes+ W+EMDXisnA5z5vsa1DJD0OPTBi4pGmR3/A== X-Google-Smtp-Source: ABdhPJzFc8lqvmlEi3AXQ8iu2dQA2CMAa+RPx/UIAg+m45d2iLu508i5BteX53i+7VKvf3AlPAb6pw== X-Received: by 2002:a05:6602:1594:: with SMTP id e20mr2346772iow.14.1634787588381; Wed, 20 Oct 2021 20:39:48 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id p3sm427766ilj.81.2021.10.20.20.39.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:39:48 -0700 (PDT) Date: Wed, 20 Oct 2021 23:39:47 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 01/11] midx.c: clean up chunkfile after reading the MIDX Message-ID: <30f6f23daf49814f479865eea5f9ee68de209d5f.1634787555.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In order to read the contents of a MIDX, we initialize a chunkfile structure which can read the table of contents and assign pointers into different sections of the file for us. We do call free(), since the chunkfile struct is heap allocated, but not the more appropriate free_chunkfile(), which also frees memory that the structure itself owns. Call that instead to avoid leaking memory in this function. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- The patch contents are from Ævar, but the message is mine. I hope that he doesn't mind me forging his sign-off here. midx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) -- 2.33.0.96.g73915697e6 diff --git a/midx.c b/midx.c index 8433086ac1..36e4754767 100644 --- a/midx.c +++ b/midx.c @@ -179,12 +179,13 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local trace2_data_intmax("midx", the_repository, "load/num_packs", m->num_packs); trace2_data_intmax("midx", the_repository, "load/num_objects", m->num_objects); + free_chunkfile(cf); return m; cleanup_fail: free(m); free(midx_name); - free(cf); + free_chunkfile(cf); if (midx_map) munmap(midx_map, midx_size); if (0 <= fd) From patchwork Thu Oct 21 03:39:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 321B4C433EF for ; Thu, 21 Oct 2021 03:39:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01BCA61186 for ; Thu, 21 Oct 2021 03:39:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230434AbhJUDmJ (ORCPT ); Wed, 20 Oct 2021 23:42:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbhJUDmH (ORCPT ); Wed, 20 Oct 2021 23:42:07 -0400 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31285C06161C for ; Wed, 20 Oct 2021 20:39:52 -0700 (PDT) Received: by mail-il1-x135.google.com with SMTP id k3so14004170ilo.7 for ; Wed, 20 Oct 2021 20:39:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5oZIj6k0qGH8oMfjn+MsLxCeO7koJJHsNfIcJTYH5d4=; b=dK8/IOtrxKQeF89N1ZYb2L0txOT0FBJ+kFVQbnEhQcm2iw6V4gmhbUUCImMMdq5OGn o0apj/Tfa9V0jZZ0XqK/2SK4u2B3j8JYpBVYTNvjnYMPxUNBQxYZ8pVoYuEhdlsLMioO P2s4IkRWAw5UbO2TIkYNH9LTmG1ggv820SNXBn+h88mTIN5hFsZ6cT93Vk1Q9OjBnq/l k3XkDQ94QNkcWy/HKCmJ2KGcLqNACbEym4EzRmZvJ6YsnKaP1RIIAn3Alsv2infIfu7L zCCggQGZnXSgwvtm49hSVoiT+14XxTtPqhG+fRxbUNr1acI0b+X864y7MkAYFwo5nGuW 4rzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5oZIj6k0qGH8oMfjn+MsLxCeO7koJJHsNfIcJTYH5d4=; b=yiiPgPjJJkUS/l9TiNqh/l/wG2jzasS7vE01l9Pxc57UCoyFjYV60+1KamE+DlwW/b 5gdWLCleN6WqRO9z/nxQtP0ysz+T1VRJPA5owartwFQsJZyycSPak5EEF5ymBSsLCe/g 7n2HP/t9kmOCBNht521xiHqcRp7gZ3+DQwOZTySq7FhvGp4AmhD9Ys9OhSCXE4PtkQY6 kG5yp+hXCkUDBC7MAOudgqAqHdF5z6wFYO6ml9RW9s18eZYTK01wSS6S/OOhqUKRyZof RAifGvbOIE26su3rYQ58sU5JrUag8wl3jIZfzmDSqdgNPbIMwSMy8jDzYnrhgmzlHBOg uU5g== X-Gm-Message-State: AOAM531qrQZqZy4GO4tUFHWoml9fKX9hRyrRGq1I1I/eAT5pNFoLcIW0 Raz8kcijuAmJsQ/23Yj4+1r+FK2lX4SZEw== X-Google-Smtp-Source: ABdhPJy602ce/85lFnobbKs2+t7DYVuJvaVtpKTsAs1Z6cveyIa32hQ2Sjt2ZfA6z8wCcDJ0YoFWMA== X-Received: by 2002:a05:6e02:1c26:: with SMTP id m6mr2004176ilh.229.1634787591499; Wed, 20 Oct 2021 20:39:51 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id a12sm1936681ilb.66.2021.10.20.20.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:39:51 -0700 (PDT) Date: Wed, 20 Oct 2021 23:39:50 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 02/11] midx.c: don't leak MIDX from verify_midx_file Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The function midx.c:verify_midx_file() allocate a MIDX struct by calling load_multi_pack_index(). But when cleaning up, it calls free() without freeing any resources associated with the MIDX. Call the more appropriate close_midx() which does free those resources, which causes t5319.3 to pass when Git is compiled with SANITIZE=leak. Signed-off-by: Taylor Blau --- midx.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/midx.c b/midx.c index 36e4754767..ad60e48468 100644 --- a/midx.c +++ b/midx.c @@ -1611,7 +1611,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag * Remaining tests assume that we have objects, so we can * return here. */ - return verify_midx_error; + goto cleanup; } if (flags & MIDX_PROGRESS) @@ -1689,7 +1689,9 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag } stop_progress(&progress); +cleanup: free(pairs); + close_midx(m); return verify_midx_error; } From patchwork Thu Oct 21 03:39:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55660C433EF for ; Thu, 21 Oct 2021 03:40:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 38F6061186 for ; Thu, 21 Oct 2021 03:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231154AbhJUDmL (ORCPT ); Wed, 20 Oct 2021 23:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230442AbhJUDmJ (ORCPT ); Wed, 20 Oct 2021 23:42:09 -0400 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1A53C061749 for ; Wed, 20 Oct 2021 20:39:54 -0700 (PDT) Received: by mail-il1-x12f.google.com with SMTP id l7so11042196iln.8 for ; Wed, 20 Oct 2021 20:39:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LCphwRaPGY8QsBu1ReFAnc9TeEz7ZWhd41/xcUdARxg=; b=dmrkINQLDpsDIrD7lLUFUxclCo6PLDuJsuS64sjP1GVAoZMBYLEkQh5N+pdDNIO/ra Jlssm/9Z5ABUho+6l/P+WFkzavAVSNBKz7Xe0Ht5Xcg917ByPx9SHtdOPefrahucb7Hf qXYeeBLzJZOh8GLpag5KQxg8U0fqi6/iOE0gj9eLScCLfExzPiojH3Pr8Di4o6Am4lQ5 4qHxXUmxVf0PSKRgEVGQI1MU9iZjvaxHYbIIu5fH+Ou7gJEkRyzSw7B8pNdta46jEo/g o0u5jR844n9JM3Dg4N6zQRDf+gWCLfLTlcIlWqi5SKJGaLGF448CSj7vac/5hK0qAmYR wQoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LCphwRaPGY8QsBu1ReFAnc9TeEz7ZWhd41/xcUdARxg=; b=iKzFZ2X+ToMrG/YXnWhWfawn+Y8dlrRZtTWfhuN0asc8AIgAa5Zr4QyJ1XbH9YAZU2 EG4fEhQu1j5HOBMJfl0jBNxrAtpkJnMGUst9ydIs79N8ia4K0pzGK0v+9M/QHQdzy5By uhyqRrMqmy5Y4RHz8IgRODomKcbIiUTFV9JgiY2uLeRonZ74qT3RMuUUQEBiBClq1vLz jwYp14maYsFP68ZZHDiMOqqsTFbhsPC886Gj/vrE+hUWjPyvgx4FfLphhbhu0STDZje5 eb+6jDb1s5gDGt3FATRyrPKrk+mh2f2O7V1HRT63EHGgGDKrr4G3IMHSEB2Pz6UWTSiR T7lQ== X-Gm-Message-State: AOAM532KQS6fNmqrKEQ3/kWzl0B6i4Fawt/AwKDbVBImu2zlt3P38f0l KLyX9Lsw0dK14ajqTFkfUSdqvyKQ1jSlFA== X-Google-Smtp-Source: ABdhPJzqBMeV7dh2BwEocsr1KRheXKVoTCLwAZbW7TRwYHn2gjJ+5X/FEx7BKziodxPv1i3hM/+FAA== X-Received: by 2002:a05:6e02:152b:: with SMTP id i11mr2026494ilu.166.1634787593912; Wed, 20 Oct 2021 20:39:53 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id r18sm1981833ilo.35.2021.10.20.20.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:39:53 -0700 (PDT) Date: Wed, 20 Oct 2021 23:39:53 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 03/11] t/helper/test-read-midx.c: free MIDX within read_midx_file() Message-ID: <5157edb41e298c2504ac0bd8b4163fc6851bc1f9.1634787555.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When calling `read_midx_file()` to show information about a MIDX or list the objects contained within it we fail to call `close_midx()`, leaking the memory allocated to store that MIDX. Fix this by calling `close_midx()` before exiting the function. We can drop the "early" return when `show_objects` is non-zero, since the next instruction is also a return. (We could just as easily put a `cleanup` label here as with previous patches. But the only other time we terminate the function early is when we fail to load a MIDX in the first place. `close_midx()` does handle a NULL argument, but the extra complexity is likely not warranted). Signed-off-by: Taylor Blau --- t/helper/test-read-midx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/helper/test-read-midx.c b/t/helper/test-read-midx.c index 9d6fa7a377..27072ba94d 100644 --- a/t/helper/test-read-midx.c +++ b/t/helper/test-read-midx.c @@ -55,9 +55,10 @@ static int read_midx_file(const char *object_dir, int show_objects) printf("%s %"PRIu64"\t%s\n", oid_to_hex(&oid), e.offset, e.p->pack_name); } - return 0; } + close_midx(m); + return 0; } From patchwork Thu Oct 21 03:39:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92A66C433EF for ; Thu, 21 Oct 2021 03:40:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 663AB60E8C for ; Thu, 21 Oct 2021 03:40:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231268AbhJUDm1 (ORCPT ); Wed, 20 Oct 2021 23:42:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230507AbhJUDmT (ORCPT ); Wed, 20 Oct 2021 23:42:19 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25CA3C061768 for ; Wed, 20 Oct 2021 20:39:57 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id g2so24397754ild.1 for ; Wed, 20 Oct 2021 20:39:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jnvYuC9YIyrSRrdpUg3msJq8OxB1kQRC4M327pK9p1w=; b=tuEpDZ5m4F0u2OFfwjmmsJc2GUwCp2uZH9Nxf+dPLWjoA6i7+phZrZxO9VJGC4LIPC Ee1vDfrpOQTLCI9Ir/ePeszPU5qXIIGZNNgasJBisiIbWpbFHanGOtR5TpsjuOooWsVL wofIQS33i7f6XKnT1Cw7i5gBNeZoPeZ/f5Om+QVnFp40rTdK+GJ3C7Cc0N7UFBMpxRKD bnevQ0XauZ/3edR3uT/CeKW8l9d+JQles1hgogL0ugqtFDR83JESr2+H7EsVHfnFOy7w 1UlZVFA7N5+6DqBxqnZUEtRKJG1etcm27H9iWvq5Db62cd7Qgj4NL5f/n3b3fl4zFK5t QrkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jnvYuC9YIyrSRrdpUg3msJq8OxB1kQRC4M327pK9p1w=; b=7gwxEL97k1HYcmGGlzuKgydfXLGKB1N05M1EWCoCgcIxXuyT6PxOJedabjzcuj4ye+ Sf9gR60xPzhmD04Ituzuw5XOgs03VTPJ0AF671SBbqvyRGZmlhQqWI/cY7nz43Tb5PDR JTvwwouIYP4DbkaE4lWGzonKRcrvHerFQuj0Tu5JsBX7tKpwGMUApbf59fYkT9Y+P5BU Ny2fdHPsBaI/fGhUy9FEFbGHePjc1NwmFcFXlkvrSHvecz/mnO97gl+D1tOCooPdRctQ gZl3zKIJuhNqmmGSX93zZvFTqFUOAVV2DLF1WFPZ1W72pKRcW5Mr1uzOGKL/06Bd7JJX o3zQ== X-Gm-Message-State: AOAM533XaoXURhewdn8R2x+yo3DzLr4Z+JDPy78Y1n3nJnMQqqKUGkJF ljeWkuDH4me9XDPAa7YleVFMOCO+ARjhVw== X-Google-Smtp-Source: ABdhPJyCp3FTmVEgZSSHNbz4xnsdNI7cuuDyhFHGb+jMGC+CqD+vwgjbtjbbHmI7NiDqg8Ei9mCn1A== X-Received: by 2002:a05:6e02:1c2b:: with SMTP id m11mr2038904ilh.307.1634787596341; Wed, 20 Oct 2021 20:39:56 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id w15sm2159949ill.23.2021.10.20.20.39.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:39:56 -0700 (PDT) Date: Wed, 20 Oct 2021 23:39:55 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 04/11] builtin/pack-objects.c: don't leak memory via arguments Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When constructing arguments to pass to setup_revision(), pack-objects only frees the memory used by that array after calling get_object_list(). Ensure that we call strvec_clear() whether or not we use the arguments array by cleaning up whenever we exit the function (and rewriting one early return to jump to a label which frees the memory and then returns). We could avoid setting this array up altogether unless we are in the if-else block that calls get_object_list(), but setting up the argument array is intermingled with lots of other side-effects, e.g.: if (exclude_promisor_objects) { use_internal_rev_list = 1; fetch_if_missing = 0; strvec_push(&rp, "--exclude-promisor-objects"); } So it would be awkward to check exclude_promisor_objects twice: first to set use_internal_rev_list and fetch_if_missing, and then again above get_object_list() to push the relevant argument onto the array. Instead, leave the array's construction alone and make sure to free it unconditionally. Signed-off-by: Taylor Blau --- builtin/pack-objects.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 1a3dd445f8..857be7826f 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -4148,11 +4148,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) read_packs_list_from_stdin(); if (rev_list_unpacked) add_unreachable_loose_objects(); - } else if (!use_internal_rev_list) + } else if (!use_internal_rev_list) { read_object_list_from_stdin(); - else { + } else { get_object_list(rp.nr, rp.v); - strvec_clear(&rp); } cleanup_preferred_base(); if (include_tag && nr_result) @@ -4162,7 +4161,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) the_repository); if (non_empty && !nr_result) - return 0; + goto cleanup; if (nr_result) { trace2_region_enter("pack-objects", "prepare-pack", the_repository); @@ -4183,5 +4182,9 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) " pack-reused %"PRIu32), written, written_delta, reused, reused_delta, reuse_packfile_objects); + +cleanup: + strvec_clear(&rp); + return 0; } From patchwork Thu Oct 21 03:39:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573695 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06EEFC433FE for ; Thu, 21 Oct 2021 03:40:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC08561183 for ; Thu, 21 Oct 2021 03:40:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbhJUDm2 (ORCPT ); Wed, 20 Oct 2021 23:42:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231238AbhJUDmW (ORCPT ); Wed, 20 Oct 2021 23:42:22 -0400 Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A9D4C06176E for ; Wed, 20 Oct 2021 20:39:59 -0700 (PDT) Received: by mail-io1-xd2f.google.com with SMTP id p142so598313iod.0 for ; Wed, 20 Oct 2021 20:39:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=s2ibN6+1k6rVkvuEOds43rdcysScrKXebfEmK8hXZJA=; b=5Vw1m71+3zCUlcupWUYtKVEItf2oGdaZIi19KiEkv64vIgPALma/CVPA6HGVwjpSYx TFRYZl117gC77Jr4nXt8koxIwDdmBB2iysjrdI5qXPvQbABYoig4A/E/gXf655Q2gKWD a3Dxdpp8i6o/dSmIIcbFUdsZjGe4xkf1F0i+/cJ4RRO3KtBJx4rYs6ADLCYTguVf9cyz VeaJzVwF4okwXtoSLsWm+fupH7H2ONmdXe+m3lmveTHJUHrsBKyvMjfTckJxNB9/hab0 CSvu0vjBE7RbOS8CNdd29y4KUi9Fmye3H/PdW5O+z1XknBLKzJ+O/RwSuVRol41gcKug NeHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=s2ibN6+1k6rVkvuEOds43rdcysScrKXebfEmK8hXZJA=; b=QWzfTRUaa3kdxsTSA4DIn0L6wv14AnWa2+01ImpQYYGGnn2KUp5k9qIT32C83fiz3E Jc1E7OWCN502cFEYSXX4d2RHSEf0EM3wxdoVTXmV6oFrYaULb8DfwHyEk15rw83rxcgn mDfiNkJapKomIn5rG+Aw5K0ihP4OYxPqYFOdCIHilYeoc6/wNukQ8OiYdB6NLSCn1rNn KCgtZeeBvu125HnNWdG2h7caZGh3Q+xLF3mepXUSwePFWxhOwK4Z2LmWFN2W1rEnAQcw SZcinZpdVSHgI+Yw694QktlUwFrvij89aZY2Jk5uEZu5ZjQW81A5kFa94qUICHi0ngJn h9Qg== X-Gm-Message-State: AOAM533u+Pq16V3x/B1g1CJ6SxPsSNPf3QmsWGU/nO2EJKOaTnluVuU2 f7okIxWxXsYiDgNni2/Kc9uARTG1n1RXkA== X-Google-Smtp-Source: ABdhPJx3RoEiGCIluy/6ysrsBgUOOm//Qxv1jKkE6BPNa5KzCHGRCefY2Sq+MdVTsWSy55gaH+3RCw== X-Received: by 2002:a5d:8f8e:: with SMTP id l14mr2317837iol.124.1634787598735; Wed, 20 Oct 2021 20:39:58 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c5sm2005069ilq.71.2021.10.20.20.39.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:39:58 -0700 (PDT) Date: Wed, 20 Oct 2021 23:39:57 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 05/11] builtin/repack.c: avoid leaking child arguments Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org `git repack` invokes a handful of child processes: one to write the actual pack, and optionally ones to repack promisor objects and update the MIDX. In none of these cases do we bother to call child_process_clear(), which frees the memory associated with each child's arguments and environment. In order to do so, tweak each function that spawns a child process to have a `cleanup` label that we always visit before returning from each function. Then, make sure that we call child_process_clear() as a part of that label. Signed-off-by: Taylor Blau --- builtin/repack.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/builtin/repack.c b/builtin/repack.c index 0b2d1e5d82..d16bab09a4 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -244,6 +244,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args, struct child_process cmd = CHILD_PROCESS_INIT; FILE *out; struct strbuf line = STRBUF_INIT; + int ret = 0; prepare_pack_objects(&cmd, args); cmd.in = -1; @@ -260,7 +261,7 @@ static void repack_promisor_objects(const struct pack_objects_args *args, if (cmd.in == -1) /* No packed objects; cmd was never started */ - return; + goto cleanup; close(cmd.in); @@ -293,7 +294,12 @@ static void repack_promisor_objects(const struct pack_objects_args *args, free(promisor_name); } fclose(out); - if (finish_command(&cmd)) + ret = finish_command(&cmd); + +cleanup: + child_process_clear(&cmd); + + if (ret) die(_("could not finish pack-objects to repack promisor objects")); } @@ -559,10 +565,10 @@ static int write_midx_included_packs(struct string_list *include, struct string_list_item *item; struct packed_git *largest = get_largest_active_pack(geometry); FILE *in; - int ret; + int ret = 0; if (!include->nr) - return 0; + goto cleanup; cmd.in = -1; cmd.git_cmd = 1; @@ -587,14 +593,19 @@ static int write_midx_included_packs(struct string_list *include, ret = start_command(&cmd); if (ret) - return ret; + goto cleanup; in = xfdopen(cmd.in, "w"); for_each_string_list_item(item, include) fprintf(in, "%s\n", item->string); fclose(in); - return finish_command(&cmd); + ret = finish_command(&cmd); + +cleanup: + child_process_clear(&cmd); + + return ret; } int cmd_repack(int argc, const char **argv, const char *prefix) @@ -608,7 +619,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) struct pack_geometry *geometry = NULL; struct strbuf line = STRBUF_INIT; struct tempfile *refs_snapshot = NULL; - int i, ext, ret; + int i, ext, ret = 0; FILE *out; int show_progress = isatty(2); @@ -794,7 +805,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) ret = start_command(&cmd); if (ret) - return ret; + goto cleanup; if (geometry) { FILE *in = xfdopen(cmd.in, "w"); @@ -819,7 +830,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) fclose(out); ret = finish_command(&cmd); if (ret) - return ret; + goto cleanup; if (!names.nr && !po_args.quiet) printf_ln(_("Nothing new to pack.")); @@ -893,7 +904,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) string_list_clear(&include, 0); if (ret) - return ret; + goto cleanup; } reprepare_packed_git(the_repository); @@ -946,12 +957,14 @@ int cmd_repack(int argc, const char **argv, const char *prefix) write_midx_file(get_object_directory(), NULL, NULL, flags); } +cleanup: string_list_clear(&names, 0); string_list_clear(&rollback, 0); string_list_clear(&existing_nonkept_packs, 0); string_list_clear(&existing_kept_packs, 0); clear_pack_geometry(geometry); strbuf_release(&line); + child_process_clear(&cmd); - return 0; + return ret; } From patchwork Thu Oct 21 03:40:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFE68C433F5 for ; Thu, 21 Oct 2021 03:40:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B201761183 for ; Thu, 21 Oct 2021 03:40:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231166AbhJUDma (ORCPT ); Wed, 20 Oct 2021 23:42:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230442AbhJUDm0 (ORCPT ); Wed, 20 Oct 2021 23:42:26 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5D11C061774 for ; Wed, 20 Oct 2021 20:40:01 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id d125so27271911iof.5 for ; Wed, 20 Oct 2021 20:40:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jH1fzBQ+o6N7ARCnMCP2GRXkwznvAiu34mObQxLor3A=; b=8N1MPRB83RaDgKgH2TnDkp4Bs4i43cYiLdTJSq/jgJFkEy3ulS/DITvV7BR/ndAYJA 2aCL74sCqNjQw7BOXgEMeV2Ur2vJ7ykkuuHCnfpuVFDFSCHA+x1uY8UTtWtTNSGqq7pk kwzlfBWQC9oWLX10dHOOb5lvsMIu25O/u9863KQher8mvQu9e9DW15G5oKVL5iQXb40s ruG4wtgvRvmFU4hqP/gkiuky7batkTwWtTIcsjhnIOx0K9CSvS2qtIXEoa0PZ/ZCnsCo 6oNSdNSjRTXdtA6puQ/J8XxSb9uMxJrgzz4W+cBHn2Cq/QQlc8UTJMiyY0R18CTLbj27 7ZCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jH1fzBQ+o6N7ARCnMCP2GRXkwznvAiu34mObQxLor3A=; b=5K5tqhFfRnABE94yAb9lD8vJ/Hjvb/q2bnD8gm6ZwEtHcpyw2/uquDzgA0AqyZjl20 H5qMwv3k+QmvUWBmpX7cE6F8uNfQXxyBdpHPzLD+U9jRk3Rum6P2szCRLAaxhlTYvbNA Y9VJNu9xN2q3AoqKBth5MQbJTdb3K0LgF6Krn3UQRc8mP9sLNgp09dgiRG/6eT4vds/d A4tRUpwYz3nSyDSaVX2a8YCKBUq5JCkyrZh1WEIDKdNo9vhftfssXEudp8VpVfpt+utT j1MVZJjSCjuvm2M62/iaSBGhNVnH74HrpSuV7d+WXKOiJZby0SHHS8wq8xcBr8LxFQfR 4gGA== X-Gm-Message-State: AOAM533pscbWPpeX64VisYuYnBiJ5ZhCBOLENe/PiNvdlZ3UBa1/64w0 GIOdZH9NtdsNvHTTHxIELoNz5J21IjTV0Q== X-Google-Smtp-Source: ABdhPJzlEebETtMtq7JpkPwZHYl0U4uBYbQTatFPBW4Vl33mWWsK+elpOGlaiDuKXmNs56cr92t+6Q== X-Received: by 2002:a05:6602:2c91:: with SMTP id i17mr2315224iow.20.1634787601109; Wed, 20 Oct 2021 20:40:01 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id l5sm2033783iln.50.2021.10.20.20.40.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:40:00 -0700 (PDT) Date: Wed, 20 Oct 2021 23:40:00 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 06/11] builtin/multi-pack-index.c: don't leak concatenated options Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The `multi-pack-index` builtin dynamically allocates an array of command-line option for each of its separate modes by calling add_common_options() to concatante the common options with sub-command specific ones. Because this operation allocates a new array, we have to be careful to remember to free it. We already do this in the repack and write sub-commands, but verify and expire don't. Rectify this by calling FREE_AND_NULL as the other modes do. Signed-off-by: Taylor Blau --- builtin/multi-pack-index.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index 075d15d706..4480ba3982 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -167,6 +167,8 @@ static int cmd_multi_pack_index_verify(int argc, const char **argv) usage_with_options(builtin_multi_pack_index_verify_usage, options); + FREE_AND_NULL(options); + return verify_midx_file(the_repository, opts.object_dir, opts.flags); } @@ -191,6 +193,8 @@ static int cmd_multi_pack_index_expire(int argc, const char **argv) usage_with_options(builtin_multi_pack_index_expire_usage, options); + FREE_AND_NULL(options); + return expire_midx_packs(the_repository, opts.object_dir, opts.flags); } From patchwork Thu Oct 21 03:40:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18381C433FE for ; Thu, 21 Oct 2021 03:40:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0220761183 for ; Thu, 21 Oct 2021 03:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231137AbhJUDmc (ORCPT ); Wed, 20 Oct 2021 23:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230453AbhJUDm0 (ORCPT ); Wed, 20 Oct 2021 23:42:26 -0400 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B130C06161C for ; Wed, 20 Oct 2021 20:40:04 -0700 (PDT) Received: by mail-io1-xd31.google.com with SMTP id r134so27254967iod.11 for ; Wed, 20 Oct 2021 20:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=CWYFBqmXuslCDXLcEsxvRiItt+CZNtKeixJGGfE6KgA=; b=HM2+rfsJ/Wae5+gE3skyxRF3iTwIPM4oqGyiqVy6hBL9Y2lYzCOk4G+tjXySH2GjQ3 Nwpr1dtDj/r/j70jgdOg2nmcT8aaeY0nL1+ZnT1UiXIXM6OdpC8igNM3H50L6PNznKGF t0NkBw+UWHmemsr9QYRwcrE/MSWMstrtfJKZeJtzDynEZ9bATgu1qglmNlHQ5dwEzkAB d6S6wHm25MSM0yx7bq4e7ZZIrXtQ1zDC71qBH180l3idAXLjxcBWeYY6u8gJuqW1ii7d ufnm5zFL7SyGu1GrYY+XdPz+oNlQx8UkV+OyxIxx3BV+X3SouCj6d/4MEa2rN2gTw4zC 6s/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=CWYFBqmXuslCDXLcEsxvRiItt+CZNtKeixJGGfE6KgA=; b=qHY9qbDPQARpwL1ObIHnAOAnttYk6VspgpuWHZ40sUoF/hvYDmgPw4ACOheS7nkFOu S1wUnvOJeGpeJ9Bj4RIOjeic+CTP7YeJoxMOZcq3UiJ1Fhpc4sDCkiuPSM9jJyNpG5UM izXg1J2eWQfDjxsuGQsVvRwJd2t8Usy4O1vypEPma8MuCucMBHakC0k6bjmMjFew24PZ LjpLkClkr/Dwu8cxZIzPItsxvczRsVKUfdYD4YuWj9IBTPhcekjGdMf//d3K/o5iU/vI wyc+IgerCjNPyCiU8Z0BNz5nhUl1VACuaR090mrBO92XoaBi8rrl8h5YCFvvcStAz5lY Iwxw== X-Gm-Message-State: AOAM5304ZmPWlMMwxvYlkBx5TAQjSuHLWvj7oVXGOL6gks5hJbf06gvv B+ilRAx+vKKVAIeKXtSoz9JEZDmZDZTz+g== X-Google-Smtp-Source: ABdhPJwgFl64lgAL4FbufXFMElJWicSii1/le7N3RjTzD3VQet5Rhun1M9ALV/Cn7hxzgyqNUYoaeA== X-Received: by 2002:a05:6602:2599:: with SMTP id p25mr2308085ioo.90.1634787603457; Wed, 20 Oct 2021 20:40:03 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id i15sm2059714ilu.24.2021.10.20.20.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:40:03 -0700 (PDT) Date: Wed, 20 Oct 2021 23:40:02 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 07/11] pack-bitmap.c: avoid leaking via midx_bitmap_filename() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To construct the path for a MIDX bitmap, midx_bitmap_filename() calls get_midx_filename(), and uses the result as an argument to xstrfmt(). But get_midx_filename() also uses xstrfmt, and it assumes that the caller will free the results. get_midx_filename() could take a strbuf and write to that, but it would make more work for every other caller. midx_bitmap_filename() could store the result of get_midx_filename() in a temporary variable which is freed before returning. But that intermediate allocation feels wasteful. Since this function is simple enough, we can instead "inline" its implementation into the xstrfmt call itself. That is a little gross, but arguably better than allocating memory unnecessarily. Signed-off-by: Taylor Blau --- pack-bitmap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pack-bitmap.c b/pack-bitmap.c index f47a0a7db4..d292e81af1 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -292,8 +292,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index) char *midx_bitmap_filename(struct multi_pack_index *midx) { - return xstrfmt("%s-%s.bitmap", - get_midx_filename(midx->object_dir), + return xstrfmt("%s/pack/multi-pack-index-%s.bitmap", + midx->object_dir, hash_to_hex(get_midx_checksum(midx))); } From patchwork Thu Oct 21 03:40:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A289DC433F5 for ; Thu, 21 Oct 2021 03:40:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 873E461183 for ; Thu, 21 Oct 2021 03:40:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231233AbhJUDmd (ORCPT ); Wed, 20 Oct 2021 23:42:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231210AbhJUDm0 (ORCPT ); Wed, 20 Oct 2021 23:42:26 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BB7BC061778 for ; Wed, 20 Oct 2021 20:40:06 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id y67so27201031iof.10 for ; Wed, 20 Oct 2021 20:40:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=3JvKg4/5+cWRfF5MfVvwjUCwpf6sym1bluzELYkWUNo=; b=qsoDxGKXWSisu1CgC4WFCeIz8vXkT/NpJW0OUFhu7cXbtf2Kc6ukPy1wgeCTR1Y3ZT BnTNaKwEBsPqbdEXIku8hElmssGDsRbk0oNCCu64WdiuKanr1cl8ZMwZGHxHS4bI1KhZ vwClnGcdSop0wMqxMC0SU1ehHjua37kspHPsWz32eGdABG8osgGr48+9WDxBVTH+iMKT gnjQuPhSg6q/z0vpIFpSy+vP+H60E0NvIlcJtC/Xq2Tqh+dqKw4J65iJFtxPwvaHxCp7 Dg53aUC/rDyOuwqWJDf7UrEjrPeVMBMUTyls+dAAwcwSWVIdBOVx8ZZxC8IhqFrvagSM BIdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=3JvKg4/5+cWRfF5MfVvwjUCwpf6sym1bluzELYkWUNo=; b=hVuigFPI3jp+c9Bi3bUj50sBjlma5BOZE/sROtiTDpVGzECCmAyCWru3Ss/Nzjoqu1 NDCLJlgs4xAvZslgiuvus9HfqK3fHlETJkfOxndDg1hGYlM4FyAZLjRBFoT6cMAzlKZP ivGGmei3IME5VHd2rvXFf5GSQ4/PuMdWVAVbUQtPoMv71DvPBM8cVKaOuvC28523DOV2 CdfyWVd+UkrJokKm4mvdWOogc9IdO0y+qQ50ngIocVl0ghUMyr9AoaiRVdXTnY9F6HuU 6GsxCY+7ooSZNk1m8087+GjmMBPz5TpIkb/8JyTr3ffwc+Hq4RY0eFTqAO7lVfSpveSE HQ7Q== X-Gm-Message-State: AOAM532lYc8h4NVEvopEkeB5sC/uVOkadmUMh2kcmOjJZLU6nIm8n7xg ETwbrtiU0s386SOD9zCztwtkZ/mtxUI= X-Google-Smtp-Source: ABdhPJwNbO3zmFgzukNQBpSlv6004yOAZ3b7ItuDMAkXqCg9GmnjHx7y4TY0fNVTQJWageqn4s85hA== X-Received: by 2002:a05:6602:140d:: with SMTP id t13mr2222402iov.176.1634787605857; Wed, 20 Oct 2021 20:40:05 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id k14sm2218895ilu.87.2021.10.20.20.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:40:05 -0700 (PDT) Date: Wed, 20 Oct 2021 23:40:05 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 08/11] pack-bitmap.c: don't leak type-level bitmaps Message-ID: <29920e773527e6e82065205ed98262ce9b01de28.1634787555.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org test_bitmap_walk() is used to implement `git rev-list --test-bitmap`, which compares the result of the on-disk bitmaps with ones generated on-the-fly during a revision walk. In fa95666a40 (pack-bitmap.c: harden 'test_bitmap_walk()' to check type bitmaps, 2021-08-24), we hardened those tests to also check the four special type-level bitmaps, but never freed those bitmaps. We should have, since each required an allocation when we EWAH-decompressed them. Free those, plugging that leak, and also free the base (the scratch-pad bitmap), too. Signed-off-by: Taylor Blau --- pack-bitmap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pack-bitmap.c b/pack-bitmap.c index d292e81af1..0f6656db02 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1721,6 +1721,12 @@ void test_bitmap_walk(struct rev_info *revs) else die("mismatch in bitmap results"); + bitmap_free(result); + bitmap_free(tdata.base); + bitmap_free(tdata.commits); + bitmap_free(tdata.trees); + bitmap_free(tdata.blobs); + bitmap_free(tdata.tags); free_bitmap_index(bitmap_git); } From patchwork Thu Oct 21 03:40:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86B89C433EF for ; Thu, 21 Oct 2021 03:40:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E8B461183 for ; Thu, 21 Oct 2021 03:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbhJUDmf (ORCPT ); Wed, 20 Oct 2021 23:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbhJUDm0 (ORCPT ); Wed, 20 Oct 2021 23:42:26 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B325C06174E for ; Wed, 20 Oct 2021 20:40:09 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id i6so7158095ila.12 for ; Wed, 20 Oct 2021 20:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=lq37b5YWq2OSusH7mkUuiR3zkwMRRYoaCH9wj3gryZ4=; b=HWqjAZRW6xNQSj6Gq4uo34Eil9+rudICFcXcjiE1CdhR3DeJcmHdZ0wvPPCaQuKlkc EcGNY57/BUQiDdMqDXGTHves5yyq6TkPyx3JfFiLHIh3rPzm1Aj0G8K1/crINjZdWRaV wr2ll7z2dND4QsrdwIJ1yGJs7yL2C5Kf+mlZ35S0BF/ONi4LkYdvCY+DfTuOXyfU24EI c0V0ANOIye1plWmY+oWg5NE9JsxUUur75Q7cjawtMPlob/LSMUPV8Dshb4/T2nfv2vqs pNkkWLx8ZN/9EEpBEGaGYCk8Nre/a4McDYlyt7zUviQjigJO6T0zTEbxeWpKGi/bCMdK lvVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=lq37b5YWq2OSusH7mkUuiR3zkwMRRYoaCH9wj3gryZ4=; b=2TAXXQzdAqwtfLcsPVyN9RsyJK4maCb3bnYBh3Y+1Y+sI3ytGOJyb3WgZmMWGkqttA DcwYdew5KymxhwURUhGmvT4po4h484/0X7D9uZZzXJLGIjMokSXF6yLWnQe+bsDfH3Ka xmObOfVQdpl6Y2r7UfPcY9YYJq4LfWfjuox4Hig7kafuI7jC64VVGLgyWRJEFxd341eF tffOx/ch8+6nUeY0IqmTFTbYr4C7+fp05tNXw99W7IzdIqPmNxFs+dJLytzXavxVztD3 HrRGkGPzAqnvMkMAdfzHjtrtwo0K/Ne1rbltyRMj3PiiFhURaJvqS+UVkbeRGG7lzTFe BCHw== X-Gm-Message-State: AOAM531EyPFwr8J6Ok0qnWFq+GY9s+su4p5CFXcq0TevU3IApcpS7C0U fw6pTrivbzkqRoxYamgYkrTSpIIj3rDCAA== X-Google-Smtp-Source: ABdhPJzCHEdZ5kbYMTM3PRjteFmBPo4ETxKbod5BEJGG0Xp3sA1xW1DKpwLM4d/J+F2SMWoGZo+cyQ== X-Received: by 2002:a92:5206:: with SMTP id g6mr2044310ilb.232.1634787608323; Wed, 20 Oct 2021 20:40:08 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c5sm2005250ilq.71.2021.10.20.20.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:40:08 -0700 (PDT) Date: Wed, 20 Oct 2021 23:40:07 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 09/11] pack-bitmap.c: more aggressively free in free_bitmap_index() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The function free_bitmap_index() is somewhat lax in what it frees. There are two notable examples: - While it does call kh_destroy_oid_map on the "bitmaps" map (which maps) commit OIDs to their corresponding bitmaps, the bitmaps themselves are not freed. Note here that we recycle already-freed ewah_bitmaps into a pool, but these are handled correctly by ewah_pool_free(). - We never bother to free the extended index's "positions" map, which we always allocate in load_bitmap(). Fix both of these. Signed-off-by: Taylor Blau --- pack-bitmap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pack-bitmap.c b/pack-bitmap.c index 0f6656db02..451ca3512c 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -1854,9 +1854,17 @@ void free_bitmap_index(struct bitmap_index *b) ewah_pool_free(b->trees); ewah_pool_free(b->blobs); ewah_pool_free(b->tags); + if (b->bitmaps) { + struct stored_bitmap *sb; + kh_foreach_value(b->bitmaps, sb, { + ewah_pool_free(sb->root); + free(sb); + }); + } kh_destroy_oid_map(b->bitmaps); free(b->ext_index.objects); free(b->ext_index.hashes); + kh_destroy_oid_pos(b->ext_index.positions); bitmap_free(b->result); bitmap_free(b->haves); if (bitmap_is_midx(b)) { From patchwork Thu Oct 21 03:40:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BC80C433EF for ; Thu, 21 Oct 2021 03:40:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E80160E8C for ; Thu, 21 Oct 2021 03:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231315AbhJUDmh (ORCPT ); Wed, 20 Oct 2021 23:42:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231228AbhJUDm1 (ORCPT ); Wed, 20 Oct 2021 23:42:27 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A933C061755 for ; Wed, 20 Oct 2021 20:40:11 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id h27so18620794ila.5 for ; Wed, 20 Oct 2021 20:40:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=Hhdlekp2cDi7IiVFDVmGe3w45HGV5elE1mgOJVNzEDA=; b=ObgTsbdNZmhn7IOspp1AAmPNaIHLg/MA92G00oQoiP/MT+Dwb14f5QuVxVeaFraD9k SAwYaTxAO5yW/OlW6bL1/OwpnZyx40+vlwOgJSFT7uaGWdNShkfSjcHb6+p8L0NPgxsv bOwkfQ+zeRlSI0hjHKViEhM3nCQ9juzywgdELCjVftZE0LzV+QrdwjUAjS06bJ+5yHJd ex04PrD2jXDL9lZj8Gbu+5ZbvObS9YCweUDYFjuhbJ+mVReoCvPt6PWhPivpJdOOaQ1v c5FVtbe0t4FuQNVEd8E16aD36dArybx+3/0Y/LdOk9QGhRQ8C9UmpvXpTI6CiOAbzQTO 2nuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=Hhdlekp2cDi7IiVFDVmGe3w45HGV5elE1mgOJVNzEDA=; b=6Dohr4bqX7oN6NBTSZ1OZYXDwE1WCZ5WNcn6klkH/wUBX/7/riaFtxJWFZ1LWDfuJY GVe/tv15jcdrFVpdUNLFPTRjvV3fJ7EiKNnA5flp0vNi3VAYUrQsy7tIvZ+yK2sqXip9 kxtDPSjYZJWuYDo8AlGA1KGwVdYpaMMIY52iboAOd+ibq2348RNpy8rjLtK+k0DbNyxx TnYfuc+VSM/vwyi8oaAg7ymNy78CPbohUPQGXGmLCUj6f2mNVQSRURDZzmM+8Ej3oYik R2WBzVuRmBnt26HOGrb36VcUKGBwl2dLwWsMPi5BillNGYX8paBnkjlAPhMqrGJukpth 4RxQ== X-Gm-Message-State: AOAM531TjOKoWNrW37uGQKbC5on4FfSCHZ0/vdjhPkeAR/uPyQMWBMsg 4bE180DfsU5tXo6ZxS+ZelB65YLusxs= X-Google-Smtp-Source: ABdhPJxjy5TJ4XEXNCO7y8WwvIlYeIS9/sAkoTOwmZI2UCx4ezpwuld0fyAw93W7f4VLK2uEgasuVg== X-Received: by 2002:a05:6e02:1b01:: with SMTP id i1mr2026716ilv.157.1634787610705; Wed, 20 Oct 2021 20:40:10 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id ay5sm2414302iob.46.2021.10.20.20.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:40:10 -0700 (PDT) Date: Wed, 20 Oct 2021 23:40:09 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 10/11] pack-bitmap-write.c: don't return without stop_progress() Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Ævar Arnfjörð Bjarmason Fix a bug that's been here since 7cc8f971085 (pack-objects: implement bitmap writing, 2013-12-21), we did not call stop_progress() if we reached the early exit in this function. We could call stop_progress() before we return, but better yet is to defer calling start_progress() until we need it. This will matter in a subsequent commit where we BUG(...) out if this happens, and matters now e.g. because we don't have a corresponding "region_end" for the progress trace2 event. Suggested-by: SZEDER Gábor Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Taylor Blau --- pack-bitmap-write.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index 9c55c1531e..cab3eaa2ac 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -575,15 +575,15 @@ void bitmap_writer_select_commits(struct commit **indexed_commits, QSORT(indexed_commits, indexed_commits_nr, date_compare); - if (writer.show_progress) - writer.progress = start_progress("Selecting bitmap commits", 0); - if (indexed_commits_nr < 100) { for (i = 0; i < indexed_commits_nr; ++i) push_bitmapped_commit(indexed_commits[i]); return; } + if (writer.show_progress) + writer.progress = start_progress("Selecting bitmap commits", 0); + for (;;) { struct commit *chosen = NULL; From patchwork Thu Oct 21 03:40:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 12573705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A4A74C433F5 for ; Thu, 21 Oct 2021 03:40:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 84E2D61183 for ; Thu, 21 Oct 2021 03:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbhJUDmg (ORCPT ); Wed, 20 Oct 2021 23:42:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230526AbhJUDm3 (ORCPT ); Wed, 20 Oct 2021 23:42:29 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1F3EC06161C for ; Wed, 20 Oct 2021 20:40:13 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id i189so27313015ioa.1 for ; Wed, 20 Oct 2021 20:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hpvvQvuQ18oOAqf45FNM/Vpxbukc7mObImDdLSArQWU=; b=guudpp4L1SCz9yoTm/hdc28swINKlC/cByuNHuZSu+XNwSw4qL2npsAPkxIJjjG5vC yENeJ8188iNMQToSqPCEPTEL8WO8B71vugdEFBgJGB1wC0ZVWc/++rPULFlGyTiCQLTg iSrgBlD95BhsUNCUQoOIEULAxPkWrv3UOEmsHNtyfdwDu7j1qq3aPNj2hc6bytDtjs0T +wiblTiJDR1OUhZylTr4j/CQ0yi7NNlo3wQK5lQV2RFsknp3VFweM005Jac6RjwqX37E HMj9J2Pldsbt2Etks+eBz7KjCamoQNMcUANnXisvtdI5QzKfPTXlJAgm3IwqcRlVOMAa VS1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hpvvQvuQ18oOAqf45FNM/Vpxbukc7mObImDdLSArQWU=; b=Einkm4ldhbjL052CVwhxzKPUhWWbNb3A5nwc0UVFFiIFphsCOxdnL1ZonSzicdBaOk wN4QC5byNp3+SDMm10z9iclT1HXe8V5zrdJzDm2/cK4FJG8a5fnVXIHknDC8B85l9ogt tvdFXd7cA/EzjH9KRUH0rEMHD7zCOifu/stSxnva2R/KoXJr7McjYejfN+pE3b3mIEaL xjP+VWSyKxjdOGQ6/8AFZWNLGYjXb1ZZOW+niDMbEIKoOdHuoC1K+DZfQ0rVKtkqj+p3 yyU+q5+IiqS69CmUnUebJZPX1RFk9huoR9q31rFLBLEYlwR0IbaSrVok37aeyn2+1ZbM AvTg== X-Gm-Message-State: AOAM533oFwQMjUymuQd1PoKAhk9cC3LBu2YR66UjOG5Tt3UX5aNohOiw YJgK6y61Jp8MlM6SLjIunb3A9fJ+C5ABng== X-Google-Smtp-Source: ABdhPJzXv62O7jCUFes1Hfy7IhwrYMulfQllnlLeB+w6HkRJl/J5GM/6FeXdiH2QZlCyHgfCdPyPsA== X-Received: by 2002:a6b:cd87:: with SMTP id d129mr2202694iog.28.1634787613182; Wed, 20 Oct 2021 20:40:13 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id u15sm2013900ilv.85.2021.10.20.20.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Oct 2021 20:40:12 -0700 (PDT) Date: Wed, 20 Oct 2021 23:40:12 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: avarab@gmail.com, dstolee@microsoft.com, peff@peff.net Subject: [PATCH 11/11] t5319: UNLEAK() the remaining leaks Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This resolves the remaining leaks uncovered by running t5319 when building with SANITIZE=leak. All of the leaks below are related to allocated memory stored in 'struct rev_info' which is never freed. We could alternatively implement a function which frees all allocated memory associated with the rev_info struct, but doing this properly is a bigger undertaking than I want to deal with right now. Instead, let's just UNLEAK() the few ones that are holding up t5319, which enables us to mark that test as TEST_PASSES_SANITIZE_LEAK. Signed-off-by: Taylor Blau --- builtin/log.c | 1 + builtin/pack-objects.c | 1 + builtin/rev-list.c | 2 ++ pack-bitmap-write.c | 2 ++ t/t5319-multi-pack-index.sh | 1 + 5 files changed, 7 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index f75d87e8d7..ad6dfacf77 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -757,6 +757,7 @@ int cmd_log(int argc, const char **argv, const char *prefix) opt.revarg_opt = REVARG_COMMITTISH; opt.tweak = log_setup_revisions_tweak; cmd_log_init(argc, argv, prefix, &rev, &opt); + UNLEAK(rev); return cmd_log_walk(&rev); } diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 857be7826f..6128a2e2a5 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3759,6 +3759,7 @@ static void get_object_list(int ac, const char **av) if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME)) die(_("bad revision '%s'"), line); } + UNLEAK(revs); warn_on_object_refname_ambiguity = save_warning; diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 36cb909eba..df3811e763 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -549,6 +549,8 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix) argc = setup_revisions(argc, argv, &revs, &s_r_opt); + UNLEAK(revs); + memset(&info, 0, sizeof(info)); info.revs = &revs; if (revs.bisect) diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c index cab3eaa2ac..742bae4f57 100644 --- a/pack-bitmap-write.c +++ b/pack-bitmap-write.c @@ -234,6 +234,8 @@ static void bitmap_builder_init(struct bitmap_builder *bb, if (prepare_revision_walk(&revs)) die("revision walk setup failed"); + UNLEAK(revs); + while ((commit = get_revision(&revs))) { struct commit_list *p = commit->parents; struct bb_commit *c_ent; diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index a3c72b68f7..9cfc3d6661 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -3,6 +3,7 @@ test_description='multi-pack-indexes' . ./test-lib.sh +TEST_PASSES_SANITIZE_LEAK=true GIT_TEST_MULTI_PACK_INDEX=0 objdir=.git/objects