[PATCH] ipcpd: Check return value of enroll_pack

  • From: Dimitri Staessens <dimitri@ouroboros.rocks>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Thu, 17 Feb 2022 18:46:29 +0100

Better to check the error code than the out parameter.

Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
---
 src/ipcpd/common/enroll.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/ipcpd/common/enroll.c b/src/ipcpd/common/enroll.c
index 090067d8..a369e016 100644
--- a/src/ipcpd/common/enroll.c
+++ b/src/ipcpd/common/enroll.c
@@ -187,7 +187,7 @@ static ssize_t enroll_pack(uint8_t ** buf)
 
         *buf = malloc(len);
         if (*buf == NULL)
-                return -1;
+                return -ENOMEM;
 
         enroll_msg__pack(&msg, *buf);
 
@@ -236,7 +236,7 @@ static void * enroll_handle(void * o)
                 enroll_msg__free_unpacked(msg, NULL);
 
                 len = enroll_pack(&reply);
-                if (reply == NULL) {
+                if (len < 0) {
                         log_err("Failed to pack enrollment message.");
                         connmgr_dealloc(COMPID_ENROLL, &conn);
                         continue;
-- 
2.35.1


Other related posts:

  • » [PATCH] ipcpd: Check return value of enroll_pack - Dimitri Staessens