Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1584984ybh; Tue, 14 Jul 2020 01:34:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyO1kgs8JYbA0yp1VMP4KjANZ7C/imrX3Y3no+REFbJmcK566CNJIMKXcmSBW3kMkEORY0Z X-Received: by 2002:a05:6402:1d3a:: with SMTP id dh26mr3422465edb.349.1594715691479; Tue, 14 Jul 2020 01:34:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594715691; cv=none; d=google.com; s=arc-20160816; b=lIMTEG29tGykUaAAVqIcs/xlU05qxiNhyfN/6yMPA3w0jpUYAXThmqgTXJOHoI1cjL PMjwW80qFBrii911bCRiuq5BhZCH3qtx8lUQ0NpsH4qvV6RwXHgK2W64NPMVUIH78ofZ o0Srk89fW8bJwM2ADbRaeakrcWUhXGdK5doQKWn+WvsRDJwSf9mhEb4ZYGeHxXv3qkJO 4sKmD7S3DnfQzDbpiHavHryk+0ljCfpbEuAikQGekGzewy0Rj/a9B8JSAu2NKrfQNcOq bVdd75PAQ4ctpr6eFv1p5KNyLWNtk+bMvkGYd1FgQ6yJqCkgVNTsWLduGo3ImLC/HmI6 JP3w== 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=+gTPnMrw8fbClDIMal5iBhBjpymXfkQpgSD0wEwLkeg=; b=hUlVRD6i9JuykdfMeM71hf8FN2eTC8PkGON7u6VcuHKvqOjxyxiySWbN50YiC8GrNj TkY7YlSbAn1KTjguZmSlxr+0QTIBwsGb2yR1O/CeX/fD03NhK/jqVlHYJl52p+7+lfN4 0pBjrx1s7aa7mmx6+1X7UAcOFAuPHGuC1lh67DRfbwLByUxbclmZmZzOM2IKjQQqQKfM dDrGSprhmAEwoYqhQzvukMl+O1cWObhFY1MiyzVYyF8tGdkP+E0y1YzkUHG1LFm09VqC VNSd2mUw655OHfTJpmw40PtroXoq5Pp1siWac5OwALHsN8nUyXt8Jy8u4fwjNafg6rDu uK+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx7si10370462edb.150.2020.07.14.01.34.29; Tue, 14 Jul 2020 01:34:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726602AbgGNIeI (ORCPT + 99 others); Tue, 14 Jul 2020 04:34:08 -0400 Received: from mail.loongson.cn ([114.242.206.163]:57054 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725884AbgGNIeH (ORCPT ); Tue, 14 Jul 2020 04:34:07 -0400 Received: from ticat.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Cxr9b5bQ1fM1MEAA--.5354S2; Tue, 14 Jul 2020 16:34:02 +0800 (CST) From: Peng Fan To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] mips/vdso: Fix resource leaks in genvdso.c Date: Tue, 14 Jul 2020 16:34:01 +0800 Message-Id: <1594715641-8492-1-git-send-email-fanpeng@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Cxr9b5bQ1fM1MEAA--.5354S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Cr4xCrWkur17WrykXr43Jrb_yoW8ZFW7pF s5uFyv9rZ2kFy7tw45J34j9FZ5AFn7XryUWr4kA3yDZFZ5X3sFy3y8GFyrtFy5Ar9Iq3yS 9anruFZ5AFs7trJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUySb7Iv0xC_Cr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC2 0s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI 0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE 14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20x vaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v2 6r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jFfO7UUUUU= X-CM-SenderInfo: xidq1vtqj6z05rqj20fqof0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Close "fd" before the return of map_vdso() and close "out_file" in main(). Signed-off-by: Peng Fan --- arch/mips/vdso/genvdso.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/mips/vdso/genvdso.c b/arch/mips/vdso/genvdso.c index be57b832..f459c7a 100644 --- a/arch/mips/vdso/genvdso.c +++ b/arch/mips/vdso/genvdso.c @@ -122,6 +122,7 @@ static void *map_vdso(const char *path, size_t *_size) if (fstat(fd, &stat) != 0) { fprintf(stderr, "%s: Failed to stat '%s': %s\n", program_name, path, strerror(errno)); + close(fd); return NULL; } @@ -130,6 +131,7 @@ static void *map_vdso(const char *path, size_t *_size) if (addr == MAP_FAILED) { fprintf(stderr, "%s: Failed to map '%s': %s\n", program_name, path, strerror(errno)); + close(fd); return NULL; } @@ -139,6 +141,7 @@ static void *map_vdso(const char *path, size_t *_size) if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0) { fprintf(stderr, "%s: '%s' is not an ELF file\n", program_name, path); + close(fd); return NULL; } @@ -150,6 +153,7 @@ static void *map_vdso(const char *path, size_t *_size) default: fprintf(stderr, "%s: '%s' has invalid ELF class\n", program_name, path); + close(fd); return NULL; } @@ -161,6 +165,7 @@ static void *map_vdso(const char *path, size_t *_size) default: fprintf(stderr, "%s: '%s' has invalid ELF data order\n", program_name, path); + close(fd); return NULL; } @@ -168,15 +173,18 @@ static void *map_vdso(const char *path, size_t *_size) fprintf(stderr, "%s: '%s' has invalid ELF machine (expected EM_MIPS)\n", program_name, path); + close(fd); return NULL; } else if (swap_uint16(ehdr->e_type) != ET_DYN) { fprintf(stderr, "%s: '%s' has invalid ELF type (expected ET_DYN)\n", program_name, path); + close(fd); return NULL; } *_size = stat.st_size; + close(fd); return addr; } @@ -297,6 +305,7 @@ int main(int argc, char **argv) } fprintf(out_file, "};\n"); + fclose(out_file); return EXIT_SUCCESS; } -- 2.1.0