From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <stable-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by dpdk.space (Postfix) with ESMTP id 7C752A0096
	for <public@inbox.dpdk.org>; Mon,  6 May 2019 16:02:16 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 5B628378B;
	Mon,  6 May 2019 16:02:16 +0200 (CEST)
Received: from mail-vs1-f67.google.com (mail-vs1-f67.google.com
 [209.85.217.67]) by dpdk.org (Postfix) with ESMTP id EA14B2E83
 for <stable@dpdk.org>; Mon,  6 May 2019 16:02:12 +0200 (CEST)
Received: by mail-vs1-f67.google.com with SMTP id s4so4016827vsl.2
 for <stable@dpdk.org>; Mon, 06 May 2019 07:02:12 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:mime-version:references:in-reply-to:from:date
 :message-id:subject:to:cc;
 bh=cGe7bKuo8PrBBmZD0OSewAYFqELywCQNkLb7OE5vEK0=;
 b=S9VndkJNmE7ns6M3KDM0Tvv3ltO9CMMIUCReP3ikQsS2Pk/vWeN585IEIwaprHzPLM
 m6fcOSsw4oIj6w9YvOUiUZijSKFd6qHKrfPhSKUhzm3Pv7VBczlMbEAsG0MFTcSlggjp
 W50BlI+ZGjlbBT9FX224w0h8BDhmHg5CgNTEASXQhSu32HNmd/gBvXPGguROxvlBoTU2
 JmYX6FuReu7EHBsuQeo+DmW+CMS9WQgbBLDRyW7QA5n1cvpX8uhSzKMSZK0klPC+uGTE
 9I/iv0wPvbEmnZkGsmNTeqjjCM+Avjrwd+EDgxGktfekIyN+d1payjRviEgpk7Mf4yvN
 CV2g==
X-Gm-Message-State: APjAAAWX6Wkreid8qemq0RDpe63C+3ZWht6YYkZ48miOY2pROzMKnqJN
 J+qCdBVpZXN/aXDtUeXsYYuN2z2ge3qdOB0K8Bmwbg==
X-Google-Smtp-Source: APXvYqx2rpKN42CQbl9KCg0RP2MJ/rs7ZSmG1PP0YJIxqhzIkmed7Z2ACX+8o+w9YDK4VTwYNiNiv+dxQdRw0zFVc5o=
X-Received: by 2002:a67:bb13:: with SMTP id m19mr1897551vsn.39.1557151331961; 
 Mon, 06 May 2019 07:02:11 -0700 (PDT)
MIME-Version: 1.0
References: <20190506131120.25140-1-aconole@redhat.com>
 <20190506134825.20706-1-aconole@redhat.com>
In-Reply-To: <20190506134825.20706-1-aconole@redhat.com>
From: David Marchand <david.marchand@redhat.com>
Date: Mon, 6 May 2019 16:02:00 +0200
Message-ID: <CAJFAV8xNWFwPjHxr8fBqduQT1FjB=xmOK=OfzaOi-esL92766A@mail.gmail.com>
To: Aaron Conole <aconole@redhat.com>
Cc: dev <dev@dpdk.org>, Herakliusz Lipiec <herakliusz.lipiec@intel.com>, 
 dpdk stable <stable@dpdk.org>, Anatoly Burakov <anatoly.burakov@intel.com>
Content-Type: text/plain; charset="UTF-8"
X-Content-Filtered-By: Mailman/MimeDel 2.1.15
Subject: Re: [dpdk-stable] [PATCH v2] ipc: unlock on failure
X-BeenThere: stable@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: patches for DPDK stable branches <stable.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/stable>,
 <mailto:stable-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/stable/>
List-Post: <mailto:stable@dpdk.org>
List-Help: <mailto:stable-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/stable>,
 <mailto:stable-request@dpdk.org?subject=subscribe>
Errors-To: stable-bounces@dpdk.org
Sender: "stable" <stable-bounces@dpdk.org>

On Mon, May 6, 2019 at 3:48 PM Aaron Conole <aconole@redhat.com> wrote:

> Reported by Coverity.
>
>
Coverity issue: 340076

Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
> Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
> Cc: stable@dpdk.org
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---
>  lib/librte_eal/common/eal_common_proc.c | 34 +++++++++++++------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/lib/librte_eal/common/eal_common_proc.c
> b/lib/librte_eal/common/eal_common_proc.c
> index d23728604..1a2259fe3 100644
> --- a/lib/librte_eal/common/eal_common_proc.c
> +++ b/lib/librte_eal/common/eal_common_proc.c
> @@ -934,7 +934,7 @@ int __rte_experimental
>  rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
>                 const struct timespec *ts)
>  {
> -       int dir_fd, ret = 0;
> +       int dir_fd, ret = -1;
>         DIR *mp_dir;
>         struct dirent *ent;
>         struct timeval now;
> @@ -947,7 +947,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         reply->msgs = NULL;
>
>         if (check_input(req) != 0)
> -               goto err;
> +               goto end;
>
>         if (internal_config.no_shconf) {
>                 RTE_LOG(DEBUG, EAL, "No shared files mode enabled, IPC is
> disabled\n");
> @@ -957,7 +957,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         if (gettimeofday(&now, NULL) < 0) {
>                 RTE_LOG(ERR, EAL, "Failed to get current time\n");
>                 rte_errno = errno;
> -               goto err;
> +               goto end;
>         }
>
>         end.tv_nsec = (now.tv_usec * 1000 + ts->tv_nsec) % 1000000000;
> @@ -969,9 +969,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>                 pthread_mutex_lock(&pending_requests.lock);
>                 ret = mp_request_sync(eal_mp_socket_path(), req, reply,
> &end);
>                 pthread_mutex_unlock(&pending_requests.lock);
> -               if (ret)
> -                       goto err;
> -               return ret;
> +               goto end;
>         }
>
>         /* for primary process, broadcast request, and collect reply 1 by
> 1 */
> @@ -979,7 +977,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         if (!mp_dir) {
>                 RTE_LOG(ERR, EAL, "Unable to open directory %s\n",
> mp_dir_path);
>                 rte_errno = errno;
> -               goto err;
> +               goto end;
>         }
>
>         dir_fd = dirfd(mp_dir);
> @@ -987,9 +985,8 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         if (flock(dir_fd, LOCK_SH)) {
>                 RTE_LOG(ERR, EAL, "Unable to lock directory %s\n",
>                         mp_dir_path);
> -               closedir(mp_dir);
>                 rte_errno = errno;
> -               goto err;
> +               goto close_end;
>         }
>
>         pthread_mutex_lock(&pending_requests.lock);
> @@ -1006,21 +1003,26 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>                  * locks on receive
>                  */
>                 if (mp_request_sync(path, req, reply, &end))
> -                       goto err;
> +                       goto unlock_end;
>         }
> +       ret = 0;
> +
> +unlock_end:
>         pthread_mutex_unlock(&pending_requests.lock);
>         /* unlock the directory */
>         flock(dir_fd, LOCK_UN);
>
> +close_end:
>         /* dir_fd automatically closed on closedir */
>         closedir(mp_dir);
> -       return ret;
>
> -err:
> -       free(reply->msgs);
> -       reply->nb_received = 0;
> -       reply->msgs = NULL;
> -       return -1;
> +end:
> +       if (ret) {
> +               free(reply->msgs);
> +               reply->nb_received = 0;
> +               reply->msgs = NULL;
> +       }
> +       return ret;
>  }
>
>  int __rte_experimental
> --
> 2.19.1
>


LGTM.
Reviewed-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand