Eliminate potential null pointer references

Static analysis tools flagged a few lines of code that could result in
null pointer references. This commit adds guards against dereferencing
the null pointer. It also logs an error, and attempts to return to the
caller gracefully.

Tested:
Installed code changes into system under test, and searched the
journal for the error messages. The new error messages were not found,
indicating there were no null pointer references under normal
conditions.

Change-Id: Id328d71ac0456024c3ecb9878f716b98c27c7c45
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/src/ncsi_util.cpp b/src/ncsi_util.cpp
index 902911d..0436987 100644
--- a/src/ncsi_util.cpp
+++ b/src/ncsi_util.cpp
@@ -180,6 +180,12 @@
              CallBack function = nullptr)
 {
     nlSocketPtr socket(nl_socket_alloc(), &::nl_socket_free);
+    if (socket == nullptr)
+    {
+        log<level::ERR>("Unable to allocate memory for the socket.");
+        return -ENOMEM;
+    }
+
     auto ret = genl_connect(socket.get());
     if (ret < 0)
     {
@@ -195,13 +201,18 @@
     }
 
     nlMsgPtr msg(nlmsg_alloc(), &::nlmsg_free);
+    if (msg == nullptr)
+    {
+        log<level::ERR>("Unable to allocate memory for the message.");
+        return -ENOMEM;
+    }
 
     auto msgHdr = genlmsg_put(msg.get(), 0, 0, driverID, 0, flags, cmd, 0);
     if (!msgHdr)
     {
         std::cerr << "Unable to add the netlink headers , COMMAND : " << cmd
                   << std::endl;
-        return -1;
+        return -ENOMEM;
     }
 
     if (package != DEFAULT_VALUE)