[PATCH 2/9] lib: reorder free() after printf("%p") statements

Thomas Haller thaller at redhat.com
Tue Jun 10 09:59:38 PDT 2014


Previously coverity was complaining about a use-after-free.
This was not a real problem, because the printf statement
does not dereferenciate the pointer. Change it to avoid
the warning.

Signed-off-by: Thomas Haller <thaller at redhat.com>
---
 lib/cache_mngr.c       | 3 ++-
 lib/msg.c              | 2 +-
 lib/object.c           | 4 ++--
 lib/route/cls/ematch.c | 3 ++-
 4 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c
index 7fb1ed0..36f5ca8 100644
--- a/lib/cache_mngr.c
+++ b/lib/cache_mngr.c
@@ -515,9 +515,10 @@ void nl_cache_mngr_free(struct nl_cache_mngr *mngr)
 	}
 
 	free(mngr->cm_assocs);
-	free(mngr);
 
 	NL_DBG(1, "Cache manager %p freed\n", mngr);
+
+	free(mngr);
 }
 
 /** @} */
diff --git a/lib/msg.c b/lib/msg.c
index 68f706e..bcf1aa8 100644
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -569,8 +569,8 @@ void nlmsg_free(struct nl_msg *msg)
 
 	if (msg->nm_refcnt <= 0) {
 		free(msg->nm_nlh);
-		free(msg);
 		NL_DBG(2, "msg %p: Freed\n", msg);
+		free(msg);
 	}
 }
 
diff --git a/lib/object.c b/lib/object.c
index 405912b..52bc873 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -185,9 +185,9 @@ void nl_object_free(struct nl_object *obj)
 	if (ops->oo_free_data)
 		ops->oo_free_data(obj);
 
-	free(obj);
-
 	NL_DBG(4, "Freed object %p\n", obj);
+
+	free(obj);
 }
 
 /** @} */
diff --git a/lib/route/cls/ematch.c b/lib/route/cls/ematch.c
index 89b5067..779bf8b 100644
--- a/lib/route/cls/ematch.c
+++ b/lib/route/cls/ematch.c
@@ -282,9 +282,10 @@ void rtnl_ematch_tree_free(struct rtnl_ematch_tree *tree)
 		return;
 
 	free_ematch_list(&tree->et_list);
-	free(tree);
 
 	NL_DBG(2, "Freed ematch tree %p\n", tree);
+
+	free(tree);
 }
 
 /**
-- 
1.9.3




More information about the libnl mailing list