[PATCH 1/2] cache_mngr: Return proper error code if nl_socket_alloc() fails

Tobias Klauser tklauser at distanz.ch
Tue Jun 17 05:58:09 PDT 2014


If nl_socket_alloc() failes in nl_cache_mngr_alloc() we would currently
return 0 due to the previous assignment of the err variable, even though
the failed allocation is an error condition. Fix this by setting err to
-NLE_NOMEM if nl_socket_alloc() fails.

Signed-off-by: Tobias Klauser <tklauser at distanz.ch>
---
 lib/cache_mngr.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/cache_mngr.c b/lib/cache_mngr.c
index 7fb1ed0..bec4bb0 100644
--- a/lib/cache_mngr.c
+++ b/lib/cache_mngr.c
@@ -173,8 +173,10 @@ int nl_cache_mngr_alloc(struct nl_sock *sk, int protocol, int flags,
 
 	/* Create and allocate socket for sync cache fills */
 	mngr->cm_sync_sock = nl_socket_alloc();
-	if (!mngr->cm_sync_sock)
+	if (!mngr->cm_sync_sock) {
+		err = -NLE_NOMEM;
 		goto errout;
+	}
 	if ((err = nl_connect(mngr->cm_sync_sock, protocol)) < 0)
 		goto errout_free_sync_sock;
 
-- 
1.7.9.5





More information about the libnl mailing list