From patchwork Sat Jul 9 23:50:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1244 Return-Path: Received: from confino.investici.org (investici.nine.ch [217.150.252.179]) by open-mesh.org (Postfix) with ESMTPS id 65A7E154153 for ; Sun, 10 Jul 2011 01:51:43 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [217.150.252.179] (confino [217.150.252.179]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 18BE0C866D; Sat, 9 Jul 2011 23:51:40 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 confino.investici.org 18BE0C866D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1310255502; bh=Havs+Ce+1ySh9I9QtZgYmfJHWQX8V/gMHeL3R1xKZKs=; h=From:To:Cc:Subject:Date:Message-Id; b=CF3bFJ26PI92kUvCoUwUq5gjMsBGsSHQcX8BXWRkPgW/I6ZZ7kN5sZT7IPLQC6o4+ JnbyNboeMKOMo23GgI6vspFVuk+ZIHzbwScUof7E8LlV9mU0lRgyB8//PE02eI0IPI 9bcRHF8l9KNll7Yw9RDXlpRiL+K7Cy230gcAi0h0= From: Antonio Quartulli To: "B.A.T.M.A.N" Date: Sun, 10 Jul 2011 01:50:57 +0200 Message-Id: <1310255457-26009-1-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 Subject: [B.A.T.M.A.N.] [PATCH] batman-adv: handle hash_add() return value in the TT code 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: Sat, 09 Jul 2011 23:51:43 -0000 hash_add() can fail and for this reason its return value has to be correctly interpreted to avoid memory leaks. Signed-off-by: Antonio Quartulli --- This patch needs "[PATCH] batman-adv: hash_add() has to discriminate on the return value" to work translation-table.c | 27 +++++++++++++++++++++------ 1 files changed, 21 insertions(+), 6 deletions(-) diff --git a/translation-table.c b/translation-table.c index fb6931d..267a287 100644 --- a/translation-table.c +++ b/translation-table.c @@ -188,6 +188,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); @@ -220,8 +221,14 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr) * (consistency check) */ tt_local_entry->flags |= TT_CLIENT_NEW; - hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig, - tt_local_entry, &tt_local_entry->hash_entry); + hash_added = hash_add(bat_priv->tt_local_hash, compare_ltt, + choose_orig, tt_local_entry, + &tt_local_entry->hash_entry); + if (hash_added != 0) + tt_local_entry_free_ref(tt_local_entry); + + if (hash_added < 0) + goto out; /* remove address from global hash if present */ tt_global_entry = tt_global_hash_find(bat_priv, addr); @@ -500,6 +507,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); @@ -519,10 +527,17 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node, tt_global_entry->roam_at = 0; atomic_set(&tt_global_entry->refcount, 2); - hash_add(bat_priv->tt_global_hash, compare_gtt, - choose_orig, tt_global_entry, - &tt_global_entry->hash_entry); - atomic_inc(&orig_node->tt_size); + hash_added = hash_add(bat_priv->tt_global_hash, compare_gtt, + choose_orig, tt_global_entry, + &tt_global_entry->hash_entry); + if (hash_added != 0) + tt_global_entry_free_ref(tt_global_entry); + + if (hash_added < 0) + goto out; + + if (!hash_added) + atomic_inc(&orig_node->tt_size); } else { if (tt_global_entry->orig_node != orig_node) { atomic_dec(&tt_global_entry->orig_node->tt_size);