[PATCH 4/9] cli: add error checking to nl-route-get about out-of-memory

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


This is mainly to appease coverity which warned about this

Signed-off-by: Thomas Haller <thaller at redhat.com>
---
 src/nl-route-get.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/nl-route-get.c b/src/nl-route-get.c
index c2f07d4..9d9a448 100644
--- a/src/nl-route-get.c
+++ b/src/nl-route-get.c
@@ -65,8 +65,12 @@ int main(int argc, char *argv[])
 		};
 
 		m = nlmsg_alloc_simple(RTM_GETROUTE, 0);
-		nlmsg_append(m, &rmsg, sizeof(rmsg), NLMSG_ALIGNTO);
-		nla_put_addr(m, RTA_DST, dst);
+		if (!m)
+			nl_cli_fatal(ENOMEM, "out of memory");
+		if (nlmsg_append(m, &rmsg, sizeof(rmsg), NLMSG_ALIGNTO) < 0)
+			nl_cli_fatal(ENOMEM, "out of memory");
+		if (nla_put_addr(m, RTA_DST, dst) < 0)
+			nl_cli_fatal(ENOMEM, "out of memory");
 
 		err = nl_send_auto_complete(sock, m);
 		nlmsg_free(m);
-- 
1.9.3




More information about the libnl mailing list