From patchwork Wed Apr 27 22:33:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 66847 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp2445086qge; Wed, 27 Apr 2016 15:37:29 -0700 (PDT) X-Received: by 10.107.201.207 with SMTP id z198mr13477749iof.120.1461796648924; Wed, 27 Apr 2016 15:37:28 -0700 (PDT) Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com. [209.132.183.37]) by mx.google.com with ESMTPS id cu7si7857107igb.76.2016.04.27.15.37.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Apr 2016 15:37:28 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RMYpDM062964; Wed, 27 Apr 2016 18:34:52 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3RMYATZ031654 for ; Wed, 27 Apr 2016 18:34:10 -0400 Received: from colepc.redhat.com (ovpn-113-44.phx2.redhat.com [10.3.113.44]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3RMY8oe021727; Wed, 27 Apr 2016 18:34:09 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Wed, 27 Apr 2016 18:33:59 -0400 Message-Id: <8946f4fef5ed3005b71f851047a77ac45d8d8935.1461796325.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/4] rpc: Add virNetMessageClearPayload X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com Handles freeing the buffer and fds, but not the message details. Use it to drop some duplicate code. --- src/rpc/virnetmessage.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/rpc/virnetmessage.c b/src/rpc/virnetmessage.c index 5c57128..3df502a 100644 --- a/src/rpc/virnetmessage.c +++ b/src/rpc/virnetmessage.c @@ -49,17 +49,25 @@ virNetMessagePtr virNetMessageNew(bool tracked) } -void virNetMessageClear(virNetMessagePtr msg) +static void +virNetMessageClearPayload(virNetMessagePtr msg) { - bool tracked = msg->tracked; size_t i; - VIR_DEBUG("msg=%p nfds=%zu", msg, msg->nfds); - for (i = 0; i < msg->nfds; i++) VIR_FORCE_CLOSE(msg->fds[i]); VIR_FREE(msg->fds); VIR_FREE(msg->buffer); +} + + +void virNetMessageClear(virNetMessagePtr msg) +{ + bool tracked = msg->tracked; + + VIR_DEBUG("msg=%p nfds=%zu", msg, msg->nfds); + + virNetMessageClearPayload(msg); memset(msg, 0, sizeof(*msg)); msg->tracked = tracked; } @@ -67,7 +75,6 @@ void virNetMessageClear(virNetMessagePtr msg) void virNetMessageFree(virNetMessagePtr msg) { - size_t i; if (!msg) return; @@ -76,10 +83,7 @@ void virNetMessageFree(virNetMessagePtr msg) if (msg->cb) msg->cb(msg, msg->opaque); - for (i = 0; i < msg->nfds; i++) - VIR_FORCE_CLOSE(msg->fds[i]); - VIR_FREE(msg->buffer); - VIR_FREE(msg->fds); + virNetMessageClearPayload(msg); VIR_FREE(msg); }