From patchwork Fri May 5 21:19:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13233037 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC767C77B7F for ; Fri, 5 May 2023 21:19:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232170AbjEEVT1 (ORCPT ); Fri, 5 May 2023 17:19:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbjEEVTV (ORCPT ); Fri, 5 May 2023 17:19:21 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 583A2270C for ; Fri, 5 May 2023 14:19:20 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6434e65d808so2528647b3a.3 for ; Fri, 05 May 2023 14:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683321559; x=1685913559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=U+fwAjQqhDzVDdDfrV6uYArp6c4TmDLQ6JN6MHucyBU=; b=Er+8rR8jNm/yF3yjjNiV1URsrNocH7aSi/p8OnnW0kFFVNagieyoP5w0O5Gm/WSIZN A969nlhoa/TumF1VzTz9tzSY4tjunHO7MC+w2QORvnCleUnUGhmLGj8LBwS3WyvcegsS Lx1wz2V0/wWLDfJnSY3Res2MstMj8cjrHc1CAaklijoW/B926Ebk2TRDL7QY9WvQOogB Gs8nLSY3WMWw2ZL5Ccp3KkiONZBi9oTTBY62SlSTOfnnFFISTf2zFutlV3Giulr4qc4L kg5WjFnDPrqjg2XLlkxdaOMKUTPQ0krJjdbL95YMYw9hAjaL4x2+zMdJqfSmJYLW5BYf MyvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683321559; x=1685913559; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=U+fwAjQqhDzVDdDfrV6uYArp6c4TmDLQ6JN6MHucyBU=; b=eORBENbe7GON7AcqlktZAiXAo+G30a+WHbMELh4fYecmw9Ff/I0wNpcN1IrVYaUWkO zYpM1N4kK/N1yDk8/yQO5WYLZQ3UjgtMBd4rDpaqWRKKH3ivT06UB3wDTFsVTbBvP5Ik XhH+C46/4uBm2VqQ5NF7y96yMeV3hsA/belT2gACe58ypHY+h/KiSYS1pJukOeQD80U4 93JxomKSw65JBMW8HSKA8Ro52ajuY0hdj1fpivBbQOleGxkDQoLBxJ8+Q46cgBXVpYpp wZIZYv19eQhJWizLZLDdI1DsJMbs07amiKcBFUkIFkYi53YHSiWST+TkNznw04GhLOMp B4gg== X-Gm-Message-State: AC+VfDzeRsTMA4WuQ65HPto59pIfEuQXN9BhTOxYdh3qHQ3z1JEWMK5N M5g0CB2ypqTIPOXG4E5Djbaqvsp18d0= X-Google-Smtp-Source: ACHHUZ5bFUxOvU9WDNtHR4Tr49evyG9ED+U7ZrZfHs7egLTv2za7pu94zA/vQM7CCr/fVFAC5Geugg== X-Received: by 2002:a05:6a00:1907:b0:643:b081:3428 with SMTP id y7-20020a056a00190700b00643b0813428mr2147070pfi.27.1683321559207; Fri, 05 May 2023 14:19:19 -0700 (PDT) Received: from localhost (187.137.203.35.bc.googleusercontent.com. [35.203.137.187]) by smtp.gmail.com with ESMTPSA id v6-20020a62a506000000b0064378c52398sm2057787pfm.25.2023.05.05.14.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 14:19:18 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/2] diff: refactor common tail part of dirstat computation Date: Fri, 5 May 2023 14:19:16 -0700 Message-ID: <20230505211917.2746751-2-gitster@pobox.com> X-Mailer: git-send-email 2.40.1-476-g69c786637d In-Reply-To: <20230505211917.2746751-1-gitster@pobox.com> References: <20230505165952.335256-1-gitster@pobox.com> <20230505211917.2746751-1-gitster@pobox.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This will become useful when we plug leaks in these two functions. Signed-off-by: Junio C Hamano --- diff.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/diff.c b/diff.c index 648f6717a5..e13d0f8b67 100644 --- a/diff.c +++ b/diff.c @@ -2971,6 +2971,19 @@ static int dirstat_compare(const void *_a, const void *_b) return strcmp(a->name, b->name); } +static void conclude_dirstat(struct diff_options *options, + struct dirstat_dir *dir, + unsigned long changed) +{ + /* This can happen even with many files, if everything was renames */ + if (!changed) + return; + + /* Show all directories with more than x% of the changes */ + QSORT(dir->files, dir->nr, dirstat_compare); + gather_dirstat(options, dir, changed, "", 0); +} + static void show_dirstat(struct diff_options *options) { int i; @@ -3060,13 +3073,7 @@ static void show_dirstat(struct diff_options *options) dir.nr++; } - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; - - /* Show all directories with more than x% of the changes */ - QSORT(dir.files, dir.nr, dirstat_compare); - gather_dirstat(options, &dir, changed, "", 0); + conclude_dirstat(options, &dir, changed); } static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *options) @@ -3104,13 +3111,7 @@ static void show_dirstat_by_line(struct diffstat_t *data, struct diff_options *o dir.nr++; } - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; - - /* Show all directories with more than x% of the changes */ - QSORT(dir.files, dir.nr, dirstat_compare); - gather_dirstat(options, &dir, changed, "", 0); + conclude_dirstat(options, &dir, changed); } static void free_diffstat_file(struct diffstat_file *f) From patchwork Fri May 5 21:19:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 13233036 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DC3C77B7D for ; Fri, 5 May 2023 21:19:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232005AbjEEVTY (ORCPT ); Fri, 5 May 2023 17:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbjEEVTV (ORCPT ); Fri, 5 May 2023 17:19:21 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C17C85262 for ; Fri, 5 May 2023 14:19:20 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1aaf91ae451so20977275ad.1 for ; Fri, 05 May 2023 14:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683321560; x=1685913560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=si/D1FtlEEhUQ9o1SxvNC4fWjv0V6oyy2fW/XLfRW0E=; b=Z9Fr1mrEQrx2Ao2GIZ3hN7mNmrnzRutwiZMPGgNlp9k/2EqaQWX+g9B2ojtjhwlGyv DiKlf46abhNaKqAxMPktrHdaHjXF4oFoCIRRmk88Lt/KjBu8tGBuBey9sttm3sXO7tQb FLMdi88cWgOY7UgSIMMeHXRvZiU8YXWPiJESGUx4/F/0Ka2Q6D+7xxjXE8TYv7WPSsyR C0yvU0MTFyUcqowct164qU/kvbpLOwGVVOi2aa/Np2lhsi+bZ3zYR/7QvwXqfgxrTU3Z iO6zZGyWog1PSvdRR8QFddMbnkIy2I2JuDJz0trPexu+pK7ufan9knVb1QVNa+lECIo9 2RPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683321560; x=1685913560; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=si/D1FtlEEhUQ9o1SxvNC4fWjv0V6oyy2fW/XLfRW0E=; b=TR10uG7grK5D14z/LpqvP1yD62d3VeVuM1aWhb3ATwO55ttxtKS6W+7GEpwo+2QAWJ 2CVtSql+IgAyZRYRY1hZlR/bNJ3upRxTWm23mAp4u+tRik4Pltr68BtVCFFtjH/bgz7f J+1n27aHoB6gWTi5zMM/g2s+MBNBaHZ4+gOGTwjs7+ySgpqak70WJ6OIuPH919my1p6C 4GA9a5ZudOz1/HokVG0RtY1IQFICSd6vJnV06HfP/qM17R7gZpJVsAjn56Scd2P2Tmy5 ga8HxUqwKE+u6SnhLiwOBbZduF50ZRGwKCHol4Uu8FoRft0SzZF2fVajZaGJtmEQAOKI OCBA== X-Gm-Message-State: AC+VfDwpabW7kkePy2y5+ZhIAd/FoJn8BiwK2KTIWDF+bg5rmrDO88C2 9BGK5uCVy1wegNhf7sRt9d6D+fZE5K4= X-Google-Smtp-Source: ACHHUZ6Z1N0firKDdx9LzKgCkWvUjHpKmS9konV6M1l4E8geNVl3JybUj4kwrQddyaq6zXbOhf8TIQ== X-Received: by 2002:a17:902:e810:b0:1aa:f6c3:ba24 with SMTP id u16-20020a170902e81000b001aaf6c3ba24mr3468463plg.4.1683321559936; Fri, 05 May 2023 14:19:19 -0700 (PDT) Received: from localhost (187.137.203.35.bc.googleusercontent.com. [35.203.137.187]) by smtp.gmail.com with ESMTPSA id bg8-20020a1709028e8800b001a96d295f15sm2177585plb.284.2023.05.05.14.19.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 May 2023 14:19:19 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/2] diff: plug leaks in dirstat Date: Fri, 5 May 2023 14:19:17 -0700 Message-ID: <20230505211917.2746751-3-gitster@pobox.com> X-Mailer: git-send-email 2.40.1-476-g69c786637d In-Reply-To: <20230505211917.2746751-1-gitster@pobox.com> References: <20230505165952.335256-1-gitster@pobox.com> <20230505211917.2746751-1-gitster@pobox.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The array of dirstat_file contained in the dirstat_dir structure is not freed after the processing ends. Unfortunately, the member that points at the array, .files, is incremented as the gather_dirstat() function recursively walks it, and this needs to be plugged by remembering the beginning of the array before gather_dirstat() mucks with it and freeing it after we are done. We can mark t4047 as leak-free. t4000, which is marked as leak-free, now can exercise dirstat in it, which will happen next. Signed-off-by: Junio C Hamano --- diff.c | 17 +++++++++++------ t/t4047-diff-dirstat.sh | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/diff.c b/diff.c index e13d0f8b67..d52db685f7 100644 --- a/diff.c +++ b/diff.c @@ -2975,13 +2975,18 @@ static void conclude_dirstat(struct diff_options *options, struct dirstat_dir *dir, unsigned long changed) { - /* This can happen even with many files, if everything was renames */ - if (!changed) - return; + struct dirstat_file *to_free = dir->files; + + if (!changed) { + /* This can happen even with many files, if everything was renames */ + ; + } else { + /* Show all directories with more than x% of the changes */ + QSORT(dir->files, dir->nr, dirstat_compare); + gather_dirstat(options, dir, changed, "", 0); + } - /* Show all directories with more than x% of the changes */ - QSORT(dir->files, dir->nr, dirstat_compare); - gather_dirstat(options, dir, changed, "", 0); + free(to_free); } static void show_dirstat(struct diff_options *options) diff --git a/t/t4047-diff-dirstat.sh b/t/t4047-diff-dirstat.sh index 7fec2cb9cd..70224c3da1 100755 --- a/t/t4047-diff-dirstat.sh +++ b/t/t4047-diff-dirstat.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='diff --dirstat tests' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # set up two commits where the second commit has these files