Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1713010ybh; Tue, 14 Jul 2020 05:31:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/LmDqcGbbgLDCq1unpOGP0CgZL9EBRvRvZ2XIGSrwacICQKjkzKW9mn7ZuiN7btnpJIQP X-Received: by 2002:a17:906:3945:: with SMTP id g5mr4506672eje.549.1594729899162; Tue, 14 Jul 2020 05:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594729899; cv=none; d=google.com; s=arc-20160816; b=BDkfSKBM6iheLUZrZDwNKYtSOVlvsJu+wv5JXD4Sook9maHcpnwcQ31Os4fKHe25v6 UMD7vnr+f95V5NmVV74JARgSQSGouAdgB3Xyp1WPvGZXEG9L35MkQNLWktLexylQvQtY J0+OSiwxK36dEg7tXNQnO6iWHKagwHeVI1V1wRRG6c/cpcS1hqI5ucwQrt7tR0pPJjek do4R9IrX6rzSf1hrSgVqU1GFv6lNAUTSfR7KS5dQSGEBxyv6J3S5tGv220lYdC6QITFx PlyvKwJZvsdisLImIU55YzMc/cazUG7rR3kN66v2sIoJebFsTHZ7NFVzB0/UIyd/pZxZ E5+Q== 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=bOS0Tf8Buoo+x2lAAPRPKfhr2i4lf5+B8Ko1ayeheyw=; b=G3sk9JZEXYooFpyrxAJvXnxNVLx56VedAFRgceiBzPvKKScDkupazSct0/iF+PZlIe SjBTlH4QGb4qXV6GgXd4pPnkv69lJnuIab5hypthlRdJHj04g3FNVY5THUfQRqhuG6WT 3oACRtVJ1FNGDfRsvjXqLGm1Mf2qRtkXSXJQQ2uzRKgamFhHQNsFTguZ5fOeub7Ixlpl r9EQ8OzU2lFuu3GTJVBQ/kSPA6OMlBlR65BYxOvuqgiKQCo/5D5gulMee9+dR7ym7BMj AO/U0C1vLYIDgNSwbJWvQK6Ck4MArGCsZPcBXvPs6oTl+ECndgnjK7G/PdOlAKFSc0tU sCHA== 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 f12si10360163ejx.143.2020.07.14.05.31.15; Tue, 14 Jul 2020 05:31:39 -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 S1727046AbgGNMa6 (ORCPT + 99 others); Tue, 14 Jul 2020 08:30:58 -0400 Received: from mail.loongson.cn ([114.242.206.163]:41886 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726041AbgGNMa6 (ORCPT ); Tue, 14 Jul 2020 08:30:58 -0400 Received: from ticat.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxf9dapQ1fV3EEAA--.990S2; Tue, 14 Jul 2020 20:30:19 +0800 (CST) From: Peng Fan To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] mips/vdso: Fix resource leaks in genvdso.c Date: Tue, 14 Jul 2020 20:30:18 +0800 Message-Id: <1594729818-7859-1-git-send-email-fanpeng@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dxf9dapQ1fV3EEAA--.990S2 X-Coremail-Antispam: 1UD129KBjvJXoW7WF4ftF1UJrW8WrW3urWktFb_yoW8tF4UpF sY9Fyv9rZ2kry7tw43J3409FZ5A3Z7Xryjgr4kA3yDZFWrX39FyrW8GFWFqFy5Aryav3yS 9a9ruFZ5Ar43t3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUk2b7Iv0xC_Zr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I 8E87Iv6xkF7I0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVW8JVWxJw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc2xSY4AK67AK6ryUMxAIw28I cxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2 IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0EwIxGrwCI 42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42 IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E 87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUI6wZUUUUU 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 --- v2: - add one missing fclose() --- arch/mips/vdso/genvdso.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/mips/vdso/genvdso.c b/arch/mips/vdso/genvdso.c index be57b832..ccba50e 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; } @@ -293,10 +301,12 @@ int main(int argc, char **argv) /* Calculate and write symbol offsets to */ if (!get_symbols(dbg_vdso_path, dbg_vdso)) { unlink(out_path); + fclose(out_file); return EXIT_FAILURE; } fprintf(out_file, "};\n"); + fclose(out_file); return EXIT_SUCCESS; } -- 2.1.0