From patchwork Sat Aug 12 12:04:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phil Sutter X-Patchwork-Id: 800901 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xV10B6yJ4z9t3C for ; Sat, 12 Aug 2017 22:10:02 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752666AbdHLMKB (ORCPT ); Sat, 12 Aug 2017 08:10:01 -0400 Received: from orbyte.nwl.cc ([151.80.46.58]:48767 "EHLO mail.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752247AbdHLMJ7 (ORCPT ); Sat, 12 Aug 2017 08:09:59 -0400 Received: from mail.nwl.cc (orbyte.nwl.cc [127.0.0.1]) by mail.nwl.cc (Postfix) with ESMTP id 576A868252; Sat, 12 Aug 2017 14:09:58 +0200 (CEST) Received: from xsao (localhost [IPv6:::1]) by mail.nwl.cc (Postfix) with ESMTP id 3A213681D7; Sat, 12 Aug 2017 14:09:58 +0200 (CEST) From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH 15/51] ipvrf: Fix error path of vrf_switch() Date: Sat, 12 Aug 2017 14:04:34 +0200 Message-Id: <20170812120510.28750-16-phil@nwl.cc> X-Mailer: git-send-email 2.13.1 In-Reply-To: <20170812120510.28750-1-phil@nwl.cc> References: <20170812120510.28750-1-phil@nwl.cc> X-Virus-Scanned: ClamAV using ClamSMTP Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Apart from trying to close(-1), this also leaked memory. Signed-off-by: Phil Sutter Acked-by: David Ahern --- ip/ipvrf.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ip/ipvrf.c b/ip/ipvrf.c index 92e2db98ca7d7..75cc026d072b8 100644 --- a/ip/ipvrf.c +++ b/ip/ipvrf.c @@ -373,12 +373,12 @@ static int vrf_switch(const char *name) /* -1 on length to add '/' to the end */ if (ipvrf_get_netns(netns, sizeof(netns) - 1) < 0) - return -1; + goto out; if (vrf_path(vpath, sizeof(vpath)) < 0) { fprintf(stderr, "Failed to get base cgroup path: %s\n", strerror(errno)); - return -1; + goto out; } /* if path already ends in netns then don't add it again */ @@ -429,13 +429,14 @@ static int vrf_switch(const char *name) snprintf(pid, sizeof(pid), "%d", getpid()); if (write(fd, pid, strlen(pid)) < 0) { fprintf(stderr, "Failed to join cgroup\n"); - goto out; + goto out2; } rc = 0; +out2: + close(fd); out: free(mnt); - close(fd); return rc; }