[PATCH] tools: Fix memleaks as reported by cppcheck

  • From: Sander Vrijders <sander.vrijders@xxxxxxxx>
  • To: ouroboros@xxxxxxxxxxxxx
  • Date: Fri, 25 May 2018 17:14:49 +0200

This fixes two memleaks which were reported by cppcheck.

Signed-off-by: Sander Vrijders <sander.vrijders@xxxxxxxx>
---
 src/tools/operf/operf_client.c | 4 +++-
 src/tools/oping/oping_client.c | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/tools/operf/operf_client.c b/src/tools/operf/operf_client.c
index 1518bdf..d299e23 100644
--- a/src/tools/operf/operf_client.c
+++ b/src/tools/operf/operf_client.c
@@ -100,8 +100,10 @@ void * writer(void * o)
         if (buf == NULL)
                 return (void *) -ENOMEM;
 
-        if (fdp == NULL)
+        if (fdp == NULL) {
+                free(buf);
                 return (void *) -EINVAL;
+        }
 
         memset(buf, 0, client.size);
 
diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c
index d026a68..97e9c8d 100644
--- a/src/tools/oping/oping_client.c
+++ b/src/tools/oping/oping_client.c
@@ -129,8 +129,10 @@ void * writer(void * o)
         if (buf == NULL)
                 return (void *) -ENOMEM;
 
-        if (fdp == NULL)
+        if (fdp == NULL) {
+                free(buf);
                 return (void *) -EINVAL;
+        }
 
         memset(buf, 0, client.size);
 
-- 
2.17.0


Other related posts:

  • » [PATCH] tools: Fix memleaks as reported by cppcheck - Sander Vrijders