From patchwork Fri Apr 11 18:22:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Weisbach X-Patchwork-Id: 3971781 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E58DB9F336 for ; Fri, 11 Apr 2014 18:22:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 171D020204 for ; Fri, 11 Apr 2014 18:22:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 29F16201FB for ; Fri, 11 Apr 2014 18:22:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754846AbaDKSWO (ORCPT ); Fri, 11 Apr 2014 14:22:14 -0400 Received: from mout.gmx.net ([212.227.15.15]:56340 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754838AbaDKSWN (ORCPT ); Fri, 11 Apr 2014 14:22:13 -0400 Received: from os-dhcp008.inf.tu-dresden.de ([141.76.49.8]) by mail.gmx.com (mrgmx103) with ESMTPSA (Nemesis) id 0M9bYB-1WhBDX1txH-00CzoO for ; Fri, 11 Apr 2014 20:22:12 +0200 From: Hannes Weisbach Reply-To: Hannes Weisbach Subject: [PATCH v2] Clean index map on exit Date: Fri, 11 Apr 2014 20:22:13 +0200 Message-Id: To: linux-rdma@vger.kernel.org Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) X-Mailer: Apple Mail (2.1874) X-Provags-ID: V03:K0:CbAMJQobAmjq+6/eJDdiu0x+5L2YTi9ebrFvtWQHNkXRGOnePKr aPDWT3ygWmFp8zyu4ZwT4hNOBa1cFblvU5wDnIb58KyLvp/fxwDDMZNb6E9hMmGK5G2V0ta tJMOhdFWSDKd20Mi2iNxqlV8wocK1gymRygfA4qYo/B7IImVxj+25Y4nyA5G/o7647q1GAJ n2WUiv9pIVZ71/HoBrKhg== Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hannes Weisbach librdmacm already has a cleanup function which releases all resources it holds. Missing from that cleanup are entries with struct index_map, which are dynamically allocated, whereas the map itself is declared static. Because librdmacm plays otherwise nicely with valgrind this patch aims to free the memory held by index map entries, mainly to reduce valgrind noise. This patch adds the function idm_free() to free all entries of an index map. A call to this function is added in the ucma_cleanup destructor. The ucma_idm struct index_map is cleaned using idm_free(). There is another struct index_map in preload.c and rsocket.c, but there are no destructors yet and I don't feel competent enough to add them. Signed-off-by: Hannes Weisbach --- src/cma.c | 1 + src/indexer.c | 8 ++++++++ src/indexer.h | 1 + 3 files changed, 10 insertions(+) diff --git a/src/cma.c b/src/cma.c index 0cf4203..a533bf9 100644 --- a/src/cma.c +++ b/src/cma.c @@ -139,6 +139,7 @@ static void ucma_cleanup(void) ibv_close_device(cma_dev_array[cma_dev_cnt].verbs); } + idm_free(&ucma_idm); fastlock_destroy(&idm_lock); free(cma_dev_array); cma_dev_cnt = 0; diff --git a/src/indexer.c b/src/indexer.c index c8e8bce..8dd8a82 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -164,3 +164,11 @@ void *idm_clear(struct index_map *idm, int index) entry[idx_entry_index(index)] = NULL; return item; } + +void idm_free(struct index_map *idm) +{ + size_t i; + for (i = 0; i < IDX_ARRAY_SIZE; i++) { + free(idm->array[i]); + } +} diff --git a/src/indexer.h b/src/indexer.h index 0c5f388..829d46b 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -89,6 +89,7 @@ struct index_map int idm_set(struct index_map *idm, int index, void *item); void *idm_clear(struct index_map *idm, int index); +void idm_free(struct index_map *idm); static inline void *idm_at(struct index_map *idm, int index) {