From patchwork Mon Nov 11 01:12:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 16200 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id BC51E44828C for ; Mon, 11 Nov 2019 03:13:17 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9E38A68A84A; Mon, 11 Nov 2019 03:13:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EF4F56883D3 for ; Mon, 11 Nov 2019 03:13:10 +0200 (EET) Received: by mail-wr1-f67.google.com with SMTP id i10so12795274wrs.7 for ; Sun, 10 Nov 2019 17:13:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U1FbyfCw2saChz3iqhE4mU11aiInBKOle1PVTUFWTa4=; b=UofVYsaHN0P/7nxnX2X8QbgLwGVIHHUAi22C1Jb7Qkl2ciG2bTislbYsCV6JJeHLn5 h84Zn+kQlrStwjcSP1VGi6lkFbG1q3bxkpDUo9MPYaRBNIXEe5zHNI/4//Z292KDs5bN 2MYfB+tBmqLYM/k/kMFM1mjXUZkJHmgsdXmi4VqBVng4a8KfbFsL721OshFVIK7vZZpT vTXOUCaj7zJ97M5KOQFjqVs/nAUEt9Soi/yMB0BgDGt5qTCP0nRxUGpu6SzQtnDTd/t4 DMFSQ/KSmQQRmbULmJwWF/N/Udbxm+m0bPVvb4t2c4cFk7zfIG+zgP5dngGkgeXO/YsD x2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=U1FbyfCw2saChz3iqhE4mU11aiInBKOle1PVTUFWTa4=; b=AqZU3ffWBdCeDgi8RxHZ21S77pWa6cGUGzH5w3KFDNu98omJafdEC6Pe50eXrfKsau nlhdTjbJnfbqZUiDG14Ed3WkPQ0WporCckVAbRVJWPN7lVzEdYDEDUAifr00kEMQ7D8b XduzAnB3deC7EFphWG2fwK75Sxwovv/fR2z4VhmViAG5YcDMgkfUCcBJxwntpNQwLKEL mi5RBW4rnfkwxfAMPchgAZ/NamwClOQUGIuxTnC4NBeFW5Vh70ssaxl6Z5liBJ1FZFTr +HqnI3d5GI5VhlP/9qD2HniKomnTFdbOn6ky480wpelU9ZdMYlFqnR4tFZhWLFIBZaX3 8NUQ== X-Gm-Message-State: APjAAAXPe5TY24FA87K2D7UbJOoczArwHKgJQ3j4JvcSVZx4C/5ddhNa wMi07tIRb9LaaoUq5T+knWKTkbF9 X-Google-Smtp-Source: APXvYqysYsBUwUok6VQ90mOs6zwl+LieERBohMdCSL/M7QIyMAtxIihfdPKodford16jh/IaIWAY5g== X-Received: by 2002:adf:aa92:: with SMTP id h18mr16555003wrc.150.1573434790110; Sun, 10 Nov 2019 17:13:10 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id c24sm33717357wrb.27.2019.11.10.17.13.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Nov 2019 17:13:09 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Nov 2019 02:12:57 +0100 Message-Id: <20191111011259.27313-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191110035406.11500-1-andreas.rheinhardt@gmail.com> References: <20191110035406.11500-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 09/11] avutil/dict: Fix memleak when using AV_DICT_APPEND X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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" 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. Signed-off-by: Andreas Rheinhardt --- libavutil/dict.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavutil/dict.c b/libavutil/dict.c index 0ea71386e5..190ef196be 100644 --- a/libavutil/dict.c +++ b/libavutil/dict.c @@ -115,8 +115,10 @@ int av_dict_set(AVDictionary **pm, const char *key, const char *value, if (oldval && flags & AV_DICT_APPEND) { size_t len = strlen(oldval) + strlen(copy_value) + 1; char *newval = av_mallocz(len); - if (!newval) + if (!newval) { + av_free(oldval); goto err_out; + } av_strlcat(newval, oldval, len); av_freep(&oldval); av_strlcat(newval, copy_value, len);