From patchwork Tue Sep 13 19:45:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37905 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp906117pzh; Tue, 13 Sep 2022 12:45:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR75FQG7JXkY5allELGxV8Z2OWhUsbgDw13bWAo2/pjK6Bq4/qXQDwwl9gN5/Upkw7pV4lzk X-Received: by 2002:a17:907:971e:b0:77b:b0f3:6473 with SMTP id jg30-20020a170907971e00b0077bb0f36473mr11272785ejc.754.1663098349676; Tue, 13 Sep 2022 12:45:49 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id js15-20020a17090797cf00b0073fc454c591si11169264ejc.153.2022.09.13.12.45.48; Tue, 13 Sep 2022 12:45:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Nz0mJ8qq; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 68CBA68BA99; Tue, 13 Sep 2022 22:45:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073072.outbound.protection.outlook.com [40.92.73.72]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F3AB68B94D for ; Tue, 13 Sep 2022 22:45:37 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YSNVtIyXEtlhW+cthLrrxv94/Cy3Cq/zxqXFvNktheF0+nAQq0sVWXzP7Z8CBNIMk88F1YhRkL3pZmtONS4Fe44tmHD0Y3R6Bb287Q6qnoG5SRmX35a+/L/D0alIW1y4eqpyQy3lP6CCqsekGg4xSx74qdhmyAyf6AcCgKzUXlXMIef1KBdUnMM2AL/F0s/mrSwmYZ9tgwAOEG0p7WxOoI821iT8DXA0nl5l2fBxQZYtp6yCufRtD/yrHslWw5ryANhgqMrM1kp4JcXBO/TkWysstPWsIQGsMM/6WxAI5R7ta4Q+k9DpCNIZAClOUlpUbP7o0GPCQCmzHu6Non4yRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HrbmX+Gj315NiSGGp1rK4SYoQpxxBcyv7YUTQN+/Y7c=; b=VP7o06WS5zQ/DonJyZkkjp3lL/yUuiOLsmBtBBzuwyIQY5KgTwl9Op29XHN/s1ICojUQ3+NFuJh4gKihWjvBBklW6y11TB1vmLspOb7/r7OV704qelh6liYW5gEGvKkdv1mH4eGF8sMQ90Le8BrXI42ea9cPC5CUbaY1KMeYlP3zOAt8qgtIY2Jc7qJirVuQt4gVPGQgy8mYiuBnIEgKtReUnY7mKj2+HH/OrTWfqBBHTuZbMg28AZROAYPO5+FVLmbmjp0eELX830RGWS1ScEVzn3mGfj2gsj43WjMNEVf4WwfXVU6+ZBHFIdTRwJZsOlFkIXT5iLiwYYfuK1dlKw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HrbmX+Gj315NiSGGp1rK4SYoQpxxBcyv7YUTQN+/Y7c=; b=Nz0mJ8qqJufmzfNyRqecIonR2uBEMpUGVgUDv56suZIbFTHP98IzFP9Ci/+FihUXlSxDHH+0YQ9jllte/tXVAENYUAK16s0gYVmuMAkvPu5ok5+SgEEafWauXxIKBEoP9uK70PeE7FhvjnbxNha+ecxINYZictDx4rhZkHFFjj/6omwc2qYcFQTtPkJFCix1AqMCNg8iuWkyKrhjRMosfKY+vGeWzJU3rjmP6GcZxrGPryy9ZptPOim95K0E/8gRp5eX5/MGfVpd8p2WXpyiTSLKS3R0sc0o1z/Ds0iEPc6HatciMdKUNWwJpgaJHPSk2wOJxV2UjrT4SKJ+V+drww== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PAXP250MB0446.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:276::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.22; Tue, 13 Sep 2022 19:45:34 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::51a4:ed23:ea45:dfeb]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::51a4:ed23:ea45:dfeb%8]) with mapi id 15.20.5612.022; Tue, 13 Sep 2022 19:45:34 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Sep 2022 21:45:28 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [z3hjaTrH7EP0Gijc9x1JsZcZPgfPSLuVqBBNDFMi8SE=] X-ClientProxiedBy: ZRAP278CA0013.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:10::23) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220913194530.775103-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PAXP250MB0446:EE_ X-MS-Office365-Filtering-Correlation-Id: 2d48f770-48bb-40ef-c701-08da95c085d4 X-MS-Exchange-SLBlob-MailProps: V85gaVfRD492Fou76aZV/OCIaSP5Lw9JhUfRx6ZaZld5gJl0z7ifueeNshDrIBz/kPUQS4XOAj9vxLaExOLkVZnmcqUVGqPgFHrV1JrwhMj95uG+vzJRMWYBRWGiTlU+YTXP6+8INM6fgxF9r2qJgl3I23EVr+SjxvwHJjG7e1loeHn5O3DfirExV/vxJg5Vn+yBJyLKpj4qIJ4SMxzKIwH21buYCTJI+B0gYgbBZORE2ech6wpUkGv4SiKNZedHHZGM9fDGbHe3XFI2tmYGlTb05XXvD67FFljxYSSFfQuFy3yePkvEOp8U9EFT7wtHX7ySjjzGURuzsZmFPDKKIRqLa8kMU0WBNA3aYEWHK9FUG8H0Gsc5eaNqAPKVIHtDS6tyciNlCPgM5Ky7ZmNrsFGqMvapz8krChmIrJ9yX/YEkH2fuhU6hgPM5+4HMigu0X5dfJkLK83TdVMIPoGnR+uJ4J7AgLZeuGcU6HO6cpUhwqMb71+S5hK6Teald3iMP0yK/Bsjit5CxWBB1C5mA8uN5NLTACnHVJO5P/M2lCeKjx4jKMKzUJ82TfhMj5axCKDLlhabijo0khZ5VwcjRxFeBYQfKUxcXG+zAbfLn1+PF+M4i5wvOOl74FJLJXwRQEr4UQeOoznLfjSrFH83e4hGcJi2uGsN18F7AjiJqHvjbspe0sh+iOc1ZNIIkFH1M83kSeMX4eXnxty6z8MOqBTOf1Acy4vQVl+FaAPAHtWh5ndA+nOZIHMCK8wvu1zn29+8RIIyZc7rcFHrlcFUB9fBj816vt5uDoVhpeC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ginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2d48f770-48bb-40ef-c701-08da95c085d4 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2022 19:45:34.0419 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXP250MB0446 Subject: [FFmpeg-devel] [PATCH 1/3] avutil/dict: Fix memleak when using AV_DICT_APPEND X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: AhxYuj8zv0sF If a key already exists in an AVDictionary and the AV_DICT_APPEND flag is set, the old entry is at first discarded from the dictionary, but a pointer to the value is kept. Lateron enough memory to store the appended string is allocated; should this allocation fail, the old string is not freed and hence leaks. This commit changes this by moving creating the combined value to an earlier point in the function, which also ensures that the AVDictionaty is unchanged in case of errors. Signed-off-by: Andreas Rheinhardt --- This is an improved version of https://patchwork.ffmpeg.org/project/ffmpeg/patch/20191111011259.27313-1-andreas.rheinhardt@gmail.com/ libavutil/dict.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/libavutil/dict.c b/libavutil/dict.c index a4f638a1fc..c01165634e 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -73,7 +73,7 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, { AVDictionary *m = *pm; AVDictionaryEntry *tag = NULL; - char *oldval = NULL, *copy_key = NULL, *copy_value = NULL; + char *copy_key = NULL, *copy_value = NULL; if (!(flags & AV_DICT_MULTIKEY)) { tag = av_dict_get(m, key, NULL, flags); @@ -97,10 +97,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, av_free(copy_value); return 0; } - if (flags & AV_DICT_APPEND) - oldval = tag->value; - else - av_free(tag->value); + if (copy_value && flags & AV_DICT_APPEND) { + size_t len = strlen(tag->value) + strlen(copy_value) + 1; + char *newval = av_mallocz(len); + if (!newval) + goto err_out; + av_strlcat(newval, tag->value, len); + av_strlcat(newval, copy_value, len); + av_freep(©_value); + copy_value = newval; + } + av_free(tag->value); av_free(tag->key); *tag = m->elems[--m->count]; } else if (copy_value) { @@ -113,17 +120,6 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, if (copy_value) { m->elems[m->count].key = copy_key; m->elems[m->count].value = copy_value; - if (oldval && flags & AV_DICT_APPEND) { - size_t len = strlen(oldval) + strlen(copy_value) + 1; - char *newval = av_mallocz(len); - if (!newval) - goto err_out; - av_strlcat(newval, oldval, len); - av_freep(&oldval); - av_strlcat(newval, copy_value, len); - m->elems[m->count].value = newval; - av_freep(©_value); - } m->count++; } else { av_freep(©_key); From patchwork Tue Sep 13 19:46:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37906 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp906475pzh; Tue, 13 Sep 2022 12:46:44 -0700 (PDT) X-Google-Smtp-Source: AA6agR5uRoDqwNz1rKC40/ip3OXro2RQ4H5u+6sFXlW54zSU3p7WKCi50NKkYuB/yqwvSkymuVMm X-Received: by 2002:a17:907:1623:b0:77e:9455:b4d9 with SMTP id hb35-20020a170907162300b0077e9455b4d9mr6396837ejc.491.1663098404186; Tue, 13 Sep 2022 12:46:44 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fj4-20020a1709069c8400b007317756bc04si9685021ejc.1006.2022.09.13.12.46.42; Tue, 13 Sep 2022 12:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Ye0oMxbH; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 951F668BAAA; Tue, 13 Sep 2022 22:46:40 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073070.outbound.protection.outlook.com [40.92.73.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1A33168B940 for ; Tue, 13 Sep 2022 22:46:33 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gew/My/OnMXsoayHD98MKM5iRanTNhoxwjllRiLQJxZqqt6orzk0FClWdvdetcBX5mrOWZkWUnF6JD2Cn/8MVL5fOqD/zasPc5Czy6CMmKxDS9bvaL4cDxRIztUc/2ClJVniuYtFf3AIr2BI/3h8tjo2IvxWa0c2DpkzxbyILnca1M0S/28TMJh1TTR4vfi8fyhGuEEaUR7q786fNeVyo1fal20Zq8LystLqy6Cd2mdPf3EcMe3TRKqLbc2FVNDAOSf4EP0D8qq7AUvMXNLptJ/liRHU+EOwJkmXA76xws+lwYbWEPPkDATZtYGti7/fVLjS3AqLHHvLQshKJZOsnw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pXvMuhoTxFT9Js6Uxe8UUrIkyRsBEvVWSuBEiOv1u2Y=; b=JBIC9W4HyKyjQxDdIZeChcbVA3XFi8e9OzBF0C/sjBUlkg8muJDIn0TMUr5VJXczEzxPs5nHZTy7iWtY87t+a/YWlY0zy33cQNfRjxlKCtxfC4p271nF6ZsctqCEPv20+GOcGuWofPm3kPogcuhqyQkSEY4RHY3LB5dC3hBrh5rbutNw6YGdG9zljCSdei0CbQQWB5hj7BD4DwK4oOMceQKDYp7EjAvCmLW9ezuVgt4OiCjQFq9QlbUDiMM+1NlwxRUt8lmPWdUWIehGNzWNkpQo9R21sHQNTBaxw+g8jofi0FxTJrpwMhPfBiyZO+xLk7jmpazIwCbpIYxWTQtJTQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pXvMuhoTxFT9Js6Uxe8UUrIkyRsBEvVWSuBEiOv1u2Y=; b=Ye0oMxbH0CFE970nKexQJZXynneOYkfyz71VaPpG/ww5kzBct21p1+1lyRzG0LEDMzhB0VUplZQN6GXqGLqj8uo5ytOrAuymcYPNjcDEc3vaTXFue4cm2+PUSqyvUtnSERo25WjruwE5vMjI43yvj/+MGDmtq2sB6jv8tBYfQC76Cs3d6pVA/puO1qKPDVryD+Rd/yM4fIRoObMTms7qiLagepxO0PMNuM2huTdkJAwZBNYJkMkzEdpz1UeDoSknAJ5MGen1dbL4rPYK25ErqDIHGWwXPk6xTqS0uxIRKBW7FzO7AkUXuNwofxuUIRKPv56SUHZnOqfvOtzjJrsoMg== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PAXP250MB0446.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:276::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.22; Tue, 13 Sep 2022 19:46:31 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::51a4:ed23:ea45:dfeb]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::51a4:ed23:ea45:dfeb%8]) with mapi id 15.20.5612.022; Tue, 13 Sep 2022 19:46:31 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Sep 2022 21:46:27 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [d4yRNiEYrwokV3a++o9qqQz1qE0bvq52JF7unBBuIlk=] X-ClientProxiedBy: ZR0P278CA0115.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:20::12) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220913194628.922446-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PAXP250MB0446:EE_ X-MS-Office365-Filtering-Correlation-Id: 31bdd4b9-ce8a-44a9-43da-08da95c0a840 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpEumVcsW5TnTvXPpg27e8v6Y3/HUwb76MXFyeGcSeWgeRKvazMioolJS7udSERk0ttLP+wf+xiwdAAD67QCAKZ2m8xZOuzTO6NWAVi76bZMOgYqvTN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FumG5McN8zHEsOKR79Ca2rpolbFicE8rnvuFfN0B/60bvQL88sg5ccuapz3gAaV5LdgXONAvzcfRyjKUM1dVAh9SisuAVYTFS3pZscVQ8CfTcufnNsd4cXpZDo9RBKhCA9Pv3kO5Q66k1cGfOyjx/ZtIAC/qrkKCwG0ilZDvdTxpxwjhUR+1MvQZ3UvGZvmJoKzrLFXipu1MKL1QbJ7PYYf/nUaCvJ0VgIWDtNaneYcEL7JPRLyJkDcFYhirYxq5WEM6qsA/nfMvGgdZopU4CD4YFPJN+8nRHxvwcOjTUj/HDFEaubS6KBdMJMKmZRGQIpyZ1QKZe20avbBKjoNRSR88iBzpUMBjEBE2XpXgshTsyDkIQXw8+fqSHMIsqGvQo3KHK9rSoGQKNgPodDlunY7h4rlBBXOCqnO2KRCjkVy+/UZC2XXErej/gnaupLa3vYq4Zhwad3qLDLtMRVW7AduaVBLJ/IUFqM2lYH5S4NCBCrkq533qRUpjTlv29eecRzddI4w+Uh+KcyrNkwWVgqnZZF5sFqgXKL8qpv9VNvQd1riM5Cj5HSI4U4h4QgvJcUtpj3wOYzEIBEzs95mCGQMSr7Zve2N X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31bdd4b9-ce8a-44a9-43da-08da95c0a840 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2022 19:46:31.7108 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXP250MB0446 Subject: [FFmpeg-devel] [PATCH 2/3] avutil/dict: Improve appending values X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: BzuCx/xgyxoS When appending two values (due to AV_DICT_APPEND), the earlier code would first zero-allocate a buffer of the required size and then copy both parts into it via av_strlcat(). This is problematic, as it leads to quadratic performance in case of frequent enlargements. Fix this by using av_realloc() (which is hopefully designed to handle such cases in a better way than simply throwing the buffer we already have away) and by copying the string via memcpy() (after all, we already calculated the strlen of both strings). Signed-off-by: Andreas Rheinhardt --- libavutil/dict.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavutil/dict.c b/libavutil/dict.c index c01165634e..1968063b0b 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -98,16 +98,17 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, return 0; } if (copy_value && flags & AV_DICT_APPEND) { - size_t len = strlen(tag->value) + strlen(copy_value) + 1; - char *newval = av_mallocz(len); + size_t oldlen = strlen(tag->value); + size_t new_part_len = strlen(copy_value); + size_t len = oldlen + new_part_len + 1; + char *newval = av_realloc(tag->value, len); if (!newval) goto err_out; - av_strlcat(newval, tag->value, len); - av_strlcat(newval, copy_value, len); + memcpy(newval + oldlen, copy_value, new_part_len + 1); av_freep(©_value); copy_value = newval; - } - av_free(tag->value); + } else + av_free(tag->value); av_free(tag->key); *tag = m->elems[--m->count]; } else if (copy_value) { From patchwork Tue Sep 13 19:46:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 37907 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp906509pzh; Tue, 13 Sep 2022 12:46:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Wo83Q0bs5qNa8pAZ+I9xTVZjsOQhx7L42Gxj1LjBPcr9101RtSaOqJx/U8pQxivTAB3LI X-Received: by 2002:a17:907:75e7:b0:77b:e654:ef23 with SMTP id jz7-20020a17090775e700b0077be654ef23mr10776284ejc.631.1663098410537; Tue, 13 Sep 2022 12:46:50 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 9-20020a170906210900b007318652a31bsi8955552ejt.577.2022.09.13.12.46.50; Tue, 13 Sep 2022 12:46:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=Wx6lUB7c; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C92868BAE4; Tue, 13 Sep 2022 22:46:45 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073070.outbound.protection.outlook.com [40.92.73.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90D8168BA90 for ; Tue, 13 Sep 2022 22:46:38 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SILyr1dENYRurRvXdBvlDnqogMf/QUcNmlVFfMhPJ7PXdfF/RLHGHoHyocXgm05mRm7C54K2aHuT/Q4yjIfNkHOx0vD4mea93jEkFwOh4305qKYNWVesQqPoqS+zOx3UZgwPUhGb2eLvIILB/3uv36kkTe2qLWfrDYyRoq3AQy7ia+ae5LB1GVlnx+LfD1nnEDyJ5wx8iyXBs4T1AYZnOFP0nMMBMPOCVl2FhWMUewTyFvAhc1KtYCM0gv329Mq1jdKByN49HT2yBBm+SNd8WnJ8U71BB8uojfKNny3t8eI3/lDKMHp4VIVzJXlBM2frOqwUbJX3agvgbR9JXUvs7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6giXAvI3Kce5Bl3T9Qpte3rM1i+Dzcr7fUDGtiH7eTk=; b=SY1ZXanakjiD8ij9D6u76ugnslwS0D4EH18LrygUYTmJZbxs82GG5k/hjB8DwXpnjsNvntQOXuxyAlTXQWhZUh1XOsvbWwl/9D2kCjxUd9qVnHRInr+CBuQ5XR5uwvboYyGDkhaTm4fjy6bqcLqMiDmYZuP6hXnBj82WR99H+BlAJL4znyeFzs+07vQqy+FUdq1ANM0P5ioLCSTk76CKt8onRdYSN1IU2CcHfa59It9WfIxPQuETgO/NVSh3n9B5seOvVBAtw6IRRuCTo+QMnipRrGh4SNJoG3IyFFmBn4tb2CZSXLVVoUhgf+RGeQzOxqMLXTu9oMv8LW81H8gwAg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6giXAvI3Kce5Bl3T9Qpte3rM1i+Dzcr7fUDGtiH7eTk=; b=Wx6lUB7c4jlvVTa1ZLEJumOdZJHEY9iFwNJY/lYfX4fHYuXwh+X++JMb4KZIXdIWUimJx1sJ3cxPxDeEgc+NCfh5y+qme2xTIHAa4c1zSFwIIbLEPzMnM2FYDEs1mdqYoG2pOLfRtFWDmnOMHEPKE52d9rdhRAfBfne+x6KxjZh0hkrXN1Pl0KcDGdAwTm4xCOYHjrwu0t6ju+QNjYikwReK7/8PMBVVGNSJdnqwyEJlHn3YUf2cknRvs96IwCXaeCvZWXJPwD46G9K7N9TbViPmgUd8ZrGuYj+GfgJRoNQ+JBkgLOBxMa/R89Qs4pvPXjKhhmgTYdg6MYeIYclZLA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PAXP250MB0446.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:276::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5612.22; Tue, 13 Sep 2022 19:46:34 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::51a4:ed23:ea45:dfeb]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::51a4:ed23:ea45:dfeb%8]) with mapi id 15.20.5612.022; Tue, 13 Sep 2022 19:46:34 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Sep 2022 21:46:28 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [5TFxFROGctiS2c9dCigwQcpIprbIgkKm64+HIDH48y0=] X-ClientProxiedBy: ZR0P278CA0115.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:20::12) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220913194628.922446-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PAXP250MB0446:EE_ X-MS-Office365-Filtering-Correlation-Id: 265de58c-7c6c-4f78-97da-08da95c0a9e1 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpEumVcsW5TnTvXPpg27e8v73j8CMZjERtIj4VMvctmUqZZkFaDpzr/t/xVMUj/o2Wcs7jSzkIQvMMP2Mj6wMVG3gKFTwJbFT14hPf1fhGjZBfKIttJagjqyjKTpBLxeEzm7fmHYpRKG+mDzDLG5yv2RlEpil+fm1anvcMMCSsffqx71J90kRMovYc9qZQoWTE5Ewn8FY9idcrSHS/Da1spdMlz+ECh937n18/GELr8lAIwLY7L4mnCCmYhqK67D1pv7+hfFRRBloefK1qg7yYcyjx+FXifu89lCNP8U9qcKQ3aa06E9I1fjNncXlTKHFIC+TbAQ4MjVCCFRhYpFgmuU0jAFxJnfTuxhOFL7BTFxHI6dmjF+VZ3LwDpZIkmKPbwlWWugmGtKEfUFEfBvWW0bUDgPV0G6988aPTpr2FIc7PvU/fjqJRGlLmuIZAXowfcChsoYuTYa7dUu2n4gh+kDqW6CnQSoRSrn8IzTJzbp+CRiBqNDxNQsD6LYoRe7dQGTWNvf6oUZmW21Ah87yg4IzUyGPJOrvTnZeBtUPx4HY/lri9VyWtYptdTcXHn8+uFyMAXwNlKzmJLJQH+Q7xBR5BfoMLkbkp/xK2i34smaHdbXfYg1jY69XyzxIc+qtN48/KQ4YMY93axWwOAy99ILXZU4QNvF8zeOAffsh8uCjyECQAOqFve3ta+ZoAb3osE9IBvgR0qL/n4xgHZFfZ+K4m2LWK+ohWkAD52qI2pgG83z3KHs7f47co84WWyCxc= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XpYdlqSspvc+KNOpF122CEehoY25z4+29OISgfvZyGLrPoElZBrsxIa9b9XbwGavZ4Z6LcTczbTL/0D80cXRGSUIuLOMZDhWdcC2lMIGf0v3d4axuePedLg+1otWvKEKreIclxH3JdGxahvgZ+462Pdz5btuoqQJyEuJDbEG+va5CHZlH9BXbZY0EUOnaKZh6K70LImj6sN97YqBE8XWAHwt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hQhQv6y2dxMOfVK4TQKne6vQz6LauWbt7qoXkzFUxmN/t9wKzJIYlRyVryg2eDVv4FKOGUx5hzAq1J40l53rAx87HoHYEkYjT2m56uIhILRnb4hKT90c3IBDI613eRoWu5ejxO89nApEEHCu4Es8jH1u9Fn7jrfylqb7KcrXLBOHkCTK2Y4ZlOokORMfsk5PwOBLIye8L6hxNpt4fO+w2ufgK3ad+Po3MzGHm6folfN9OkJdhc5QwZggOw3hWkHTGPgde1lspmusTwIpUYFyN+Ily5jWRvuYH3GQ77nQdsOUQvH2ECpbCRt3f9OlgBnMVVua9T3poiUXuIazXK+3pl0/nRQTVEr+u16ld9KKB5kZZ06fGw5l2RGth/KtS0lZIOSJOnqBKnUb//QXs/7oTH5RJp3u4EKBuYnB0vZovUoXULV4XYJCH3/VyzJIwO9Nss+uDxuekFjpXwrJo+Kf1CQSnTIrjbs14lBdcXGLghvmREbKrggrj5hQRq17yD1EvEFFBz3fLM6JO8GSZgKVAm9IoHIw0d1Bo2goBXjSKLSDWHKUfmEhDnw6eBitegK1t46ztdyZJvr+sefy3kEF9/Rvaa4yQ/aHj47KytVkuodDq/TMG6tokjkwl5G5D8131zpEtCAzpxeyM5c/twoGnMv82V5FoeC1o46HXWHUP34pT40qWRhdswZmcvix1TNeLUr7Fj7Ez3NCReuj+u6pw6t9bbLwrdIPCnjIA0Wa7VH2bfUYAFPB8 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 265de58c-7c6c-4f78-97da-08da95c0a9e1 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2022 19:46:34.4939 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXP250MB0446 Subject: [FFmpeg-devel] [PATCH 3/3] avutil/dict: Avoid check whose result is known in advance X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HSJ76dss4vBh We know that an AVDictionary is not empty if we have just added an entry to it, so only check for it being empty on the branch that does not do so. Signed-off-by: Andreas Rheinhardt --- libavutil/dict.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavutil/dict.c b/libavutil/dict.c index 1968063b0b..4bba041d0a 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -123,12 +123,12 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, m->elems[m->count].value = copy_value; m->count++; } else { + if (!m->count) { + av_freep(&m->elems); + av_freep(pm); + } av_freep(©_key); } - if (!m->count) { - av_freep(&m->elems); - av_freep(pm); - } return 0;