From patchwork Wed Nov 2 09:42:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Wunderlich X-Patchwork-Id: 1346 Return-Path: Received: from cora.hrz.tu-chemnitz.de (cora.hrz.tu-chemnitz.de [134.109.228.40]) by open-mesh.org (Postfix) with ESMTPS id C0D906007C8 for ; Wed, 2 Nov 2011 10:42:54 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@tu-chemnitz.de; dkim-adsp=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tu-chemnitz.de; s=dkim2010; h=Message-Id:Date:Subject:Cc:To:From; bh=/Cg+9oy4y/WBbi45DGXDMT780Xmmp1AJTpAOyW4tj20=; b=ZuzW8MVSdKeb1O7Kz4Pvhl7h4JuCmGzVTjVw/a3PnujYeBNzYltHVu81u0NHFQwzhKlVLtdFtCLtqgGyWHm+sJODakKPrmwwvCAi2btD8Y5wAtU3nvGVURneF6HHx/V3+suzuGNvdDQfrX9BMfJF/zUkNdhDntXn0MB4L1nD8FY=; Received: from p57aa0d78.dip0.t-ipconnect.de ([87.170.13.120] helo=pandem0nium) by cora.hrz.tu-chemnitz.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1RLXLR-0005Oc-O7; Wed, 02 Nov 2011 10:42:54 +0100 Received: from dotslash by pandem0nium with local (Exim 4.72) (envelope-from ) id 1RLXLQ-0001bC-H5; Wed, 02 Nov 2011 10:42:52 +0100 From: Simon Wunderlich To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 2 Nov 2011 10:42:49 +0100 Message-Id: <1320226969-6117-1-git-send-email-siwu@hrz.tu-chemnitz.de> X-Mailer: git-send-email 1.7.2.5 X-Spam-Score: -1.0 (-) X-Spam-Report: --- Textanalyse SpamAssassin 3.3.1 (-1.0 Punkte) Fragen an/questions to: Postmaster TU Chemnitz * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP --- Ende Textanalyse X-Scan-Signature: 89144daf9aed2af8c7ee6fe482017aa6 Cc: Simon Wunderlich Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: check return value for hash_add() X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Nov 2011 09:42:55 -0000 if hash_add() fails, we should remove the structure to avoid memory leaks. Signed-off-by: Simon Wunderlich --- As this was the last unchecked occurence, this should close bug #136 in the open-mesh.org redmine bugtracker. --- translation-table.c | 22 ++++++++++++++++++---- 1 files changed, 18 insertions(+), 4 deletions(-) diff --git a/translation-table.c b/translation-table.c index 5b60aba..1390179 100644 --- a/translation-table.c +++ b/translation-table.c @@ -190,6 +190,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, struct bat_priv *bat_priv = netdev_priv(soft_iface); struct tt_local_entry *tt_local_entry = NULL; struct tt_global_entry *tt_global_entry = NULL; + int hash_added; tt_local_entry = tt_local_hash_find(bat_priv, addr); @@ -217,16 +218,22 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr, if (compare_eth(addr, soft_iface->dev_addr)) tt_local_entry->common.flags |= TT_CLIENT_NOPURGE; - tt_local_event(bat_priv, addr, tt_local_entry->common.flags); - /* The local entry has to be marked as NEW to avoid to send it in * a full table response going out before the next ttvn increment * (consistency check) */ tt_local_entry->common.flags |= TT_CLIENT_NEW; - hash_add(bat_priv->tt_local_hash, compare_tt, choose_orig, + hash_added = hash_add(bat_priv->tt_local_hash, compare_tt, choose_orig, &tt_local_entry->common, &tt_local_entry->common.hash_entry); + if (unlikely(!hash_added)) { + /* remove the reference for the hash */ + tt_local_entry_free_ref(tt_local_entry); + goto out; + } + + tt_local_event(bat_priv, addr, tt_local_entry->common.flags); + /* remove address from global hash if present */ tt_global_entry = tt_global_hash_find(bat_priv, addr); @@ -499,6 +506,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, struct tt_global_entry *tt_global_entry; struct orig_node *orig_node_tmp; int ret = 0; + int hash_added; tt_global_entry = tt_global_hash_find(bat_priv, tt_addr); @@ -518,9 +526,15 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, tt_global_entry->ttvn = ttvn; tt_global_entry->roam_at = 0; - hash_add(bat_priv->tt_global_hash, compare_tt, + hash_added = hash_add(bat_priv->tt_global_hash, compare_tt, choose_orig, &tt_global_entry->common, &tt_global_entry->common.hash_entry); + + if (unlikely(!hash_added)) { + /* remove the reference for the hash */ + tt_global_entry_free_ref(tt_global_entry); + goto out; + } atomic_inc(&orig_node->tt_size); } else { if (tt_global_entry->orig_node != orig_node) {