From patchwork Sat May 24 01:20:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Hefty, Sean" X-Patchwork-Id: 4236371 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9CA2DBF90B for ; Sat, 24 May 2014 01:20:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D48B3203B8 for ; Sat, 24 May 2014 01:20:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CE00320260 for ; Sat, 24 May 2014 01:20:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751011AbaEXBUa (ORCPT ); Fri, 23 May 2014 21:20:30 -0400 Received: from mga09.intel.com ([134.134.136.24]:3388 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750985AbaEXBU3 (ORCPT ); Fri, 23 May 2014 21:20:29 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 23 May 2014 18:15:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.98,897,1392192000"; d="scan'208";a="516930652" Received: from cst-linux.jf.intel.com ([10.23.221.72]) by orsmga001.jf.intel.com with ESMTP; 23 May 2014 18:20:27 -0700 From: sean.hefty@intel.com To: linux-rdma@vger.kernel.org, hannes_weisbach@gmx.net Cc: Sean Hefty Subject: [PATCH] indexer: Free index_map resources when cleared Date: Fri, 23 May 2014 18:20:17 -0700 Message-Id: <1400894417-23657-1-git-send-email-sean.hefty@intel.com> X-Mailer: git-send-email 1.7.3 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.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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: Sean Hefty Free memory allocated for index map entries when they are no longer in use. To handle this, count the number of entries stored by the index map item arrays and release the arrays when no items are being tracked. This reduces valgrind noise. Problem reported by: Hannes Weisbach Signed-off-by: Sean Hefty --- src/indexer.c | 5 +++++ src/indexer.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/indexer.c b/src/indexer.c index c8e8bce..b9e400b 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -151,6 +151,7 @@ int idm_set(struct index_map *idm, int index, void *item) entry = idm->array[idx_array_index(index)]; entry[idx_entry_index(index)] = item; + idm->count[idx_array_index(index)]++; return index; } @@ -162,5 +163,9 @@ void *idm_clear(struct index_map *idm, int index) entry = idm->array[idx_array_index(index)]; item = entry[idx_entry_index(index)]; entry[idx_entry_index(index)] = NULL; + if (--idm->count[idx_array_index(index)] == 0) { + free(idm->array[idx_array_index(index)]); + idm->array[idx_array_index(index)] = NULL; + } return item; } diff --git a/src/indexer.h b/src/indexer.h index 0c5f388..fc8eae2 100644 --- a/src/indexer.h +++ b/src/indexer.h @@ -85,6 +85,7 @@ static inline void *idx_at(struct indexer *idx, int index) struct index_map { void **array[IDX_ARRAY_SIZE]; + int count[IDX_ARRAY_SIZE]; }; int idm_set(struct index_map *idm, int index, void *item);