Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp509457ybl; Thu, 15 Aug 2019 22:55:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKtYJ/DV1qVdUeKSVyPjJnibGogr72YfLRuFN1jmBZ07XUg7eiaYHuCBwUf5KuKf+7g/jQ X-Received: by 2002:a63:7e1d:: with SMTP id z29mr6368483pgc.346.1565934908960; Thu, 15 Aug 2019 22:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565934908; cv=none; d=google.com; s=arc-20160816; b=FhfX93Bf89yk9wSFXKOOJGo7BQMWbW7rUQHeQ++FMHngFksUarPvosTs8Xk6TfS7Vn QYIXQuW2xurXmRJE1jYkk2HnytpgmYcentUepEwEYdWe8cI4GSHVlkRphr69sncd+vZ3 ya5/gPxsD1jWJH3KZ/xABR7Mp4D6Tuv1Rspyso/vH6yiC26Q8fV2kYDw1dzSj8LnKx+V qkYYOgYYzTsIpV7uNy+EJWl6+rqwTPgDWzmt/ibxZajjf+q7PoIGsp0yYV2OX4e55tU1 /b4lwDuk5FST2HdX0pwmASbTQVv3lxrg8jZ2Lub8JF9mmQx+CDGUjGhnBNtCfXmQndUF iqUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=UYipLE04l+hV469SmbY4XrY4oOZqtnVNPF3gQkQCll8=; b=OxxuJ3l74A+IYwGaGCcmn6EKNpHNrMesHNUH1ps3zlAkku+SUa8ON76fYBxbd6MZrH ko30A06yyDnESgYnzs7U0OGABMjiUCSfjRfwzUpSVLw7wA2zpnuuNc758T2DLBhocQlP O+/IA8EiBalDU0tnkWF6RP+suiicyAXY5ofamZlg3RoCuBx+T7mU08KVXD4Wc1C2XzoD wyFSBY5dH/EdC+OxZemTGZl51YZ/96ziHsxEAk1TSAXcEk5PMSTitQBZejpV5Kz+7/Jn PIZEzO2sUtEvSp3EGF/CMlYF0OvKK5jqTRGu8mtsFuzTaqA+BL0Wtphqil/fxSUbEtT0 7eig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t143si3153184pgb.542.2019.08.15.22.54.50; Thu, 15 Aug 2019 22:55:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726591AbfHPFyE (ORCPT + 99 others); Fri, 16 Aug 2019 01:54:04 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:46200 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbfHPFyE (ORCPT ); Fri, 16 Aug 2019 01:54:04 -0400 Received: by mail-yw1-f65.google.com with SMTP id w10so1438066ywa.13; Thu, 15 Aug 2019 22:54:03 -0700 (PDT) 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; bh=UYipLE04l+hV469SmbY4XrY4oOZqtnVNPF3gQkQCll8=; b=iMqSP6pGnWAXHewOT3BbWgAvUi94n5G+ox/HqhKY6PF5taiLU3VDjV7Tu6VYI2ngj7 B5DdnfxowmYupREgTLAevB+NAvIF21PcRM405wUysuglUm/ICVmvMhwLgaxyDBQjcMhJ i5M66NoLqSFram2SlhyJ0PfhSqVy9IpblbNZM/0nHIR5bdsOgix/s4HKk4/Xtt3Uljgq 3dKLOgpo6a/3Q6qG8KDwibY7QlLYP7cx/LSn2UL8GdsbIX1rbZKg/BCWN+YMg6TLSrOY Xm9ztZHgGKVCDVXLsSKbwwOpfKMESl0SkSZnezjSQkK2ouQQtmNIDUXdRiN5syZxeiu4 N15Q== X-Gm-Message-State: APjAAAWgI+JQCXcU7jAb345+g61tauZZR2wsOg1OMAZYtCO7qOAENYFF BSy7M+nAjJJTu3lGTpHgLiw= X-Received: by 2002:a81:1cc1:: with SMTP id c184mr5901885ywc.297.1565934843404; Thu, 15 Aug 2019 22:54:03 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id b64sm1052332ywe.43.2019.08.15.22.54.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Aug 2019 22:54:02 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Sumit Semwal , Gustavo Padovan , linux-media@vger.kernel.org (open list:SYNC FILE FRAMEWORK), dri-devel@lists.freedesktop.org (open list:SYNC FILE FRAMEWORK), linaro-mm-sig@lists.linaro.org (moderated list:DMA BUFFER SHARING FRAMEWORK), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] dma-buf: fix a memory leak bug Date: Fri, 16 Aug 2019 00:53:57 -0500 Message-Id: <1565934837-6471-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In sync_file_merge(), 'fences' is firstly allocated through kcalloc(). Later on, if the size is not sufficient, krealloc() is invoked to reallocate 'nfences', which is assigned to 'fences'. However, if krealloc() fails, 'fences' is not deallocated, leading to a memory leak bug. To fix the above issue, free 'fences' before go to the 'err' label. Signed-off-by: Wenwen Wang --- drivers/dma-buf/sync_file.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index ee4d1a9..6e2b2d3 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -272,8 +272,10 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a, if (num_fences > i) { nfences = krealloc(fences, i * sizeof(*fences), GFP_KERNEL); - if (!nfences) + if (!nfences) { + kfree(fences); goto err; + } fences = nfences; } -- 2.7.4