libnl: nl_socket_alloc() Bugfix
Clear memory and allow kernel to set local socket pid
Change-Id: I274156fa7bcf8d2fe78f719fb2eb32d963682931
diff --git a/libnl_2/socket.c b/libnl_2/socket.c
index 1a2255e..3bcf210 100644
--- a/libnl_2/socket.c
+++ b/libnl_2/socket.c
@@ -33,12 +33,14 @@
/* Allocate new netlink socket. */
struct nl_sock *nl_socket_alloc(void)
{
- struct nl_sock *sk = (struct nl_sock *) malloc(sizeof(struct nl_sock));
+ struct nl_sock *sk;
struct timeval tv;
struct nl_cb *cb;
+ sk = (struct nl_sock *) malloc(sizeof(struct nl_sock));
if (!sk)
goto fail;
+ memset(sk, 0, sizeof(*sk));
/* Get current time */
@@ -49,7 +51,7 @@
/* Create local socket */
sk->s_local.nl_family = AF_NETLINK;
- sk->s_local.nl_pid = getpid();
+ sk->s_local.nl_pid = 0; /* Kernel fills in pid */
sk->s_local.nl_groups = 0; /* No groups */
/* Create peer socket */
@@ -76,14 +78,13 @@
{
struct nl_sock *sk = nl_socket_alloc();
if (!sk)
- goto fail;
+ return NULL;
sk->s_cb = cb;
nl_cb_get(cb);
return sk;
-fail:
- return NULL;
+
}
/* Free a netlink socket. */