diff mbox series

[06/19] Removed bad frees from nfs/xcommon.c

Message ID 20190508133536.6077-7-steved@redhat.com (mailing list archive)
State New, archived
Headers show
Series Covertity Scan: Removed resources leaks | expand

Commit Message

Steve Dickson May 8, 2019, 1:35 p.m. UTC
nfs/xcommon.c:63: incorrect_free: "free" frees incorrect pointer "(void *)s".
nfs/xcommon.c:81: incorrect_free: "free" frees incorrect pointer "(void *)s".

Signed-off-by: Steve Dickson <steved@redhat.com>
---
 support/nfs/xcommon.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/support/nfs/xcommon.c b/support/nfs/xcommon.c
index 14e580e..3989f0b 100644
--- a/support/nfs/xcommon.c
+++ b/support/nfs/xcommon.c
@@ -53,14 +53,17 @@  char *
 xstrconcat3 (const char *s, const char *t, const char *u) {
      char *res;
 
-     if (!s) s = "";
+     int dofree = 1;
+
+     if (!s) s = "", dofree=0;
      if (!t) t = "";
      if (!u) u = "";
      res = xmalloc(strlen(s) + strlen(t) + strlen(u) + 1);
      strcpy(res, s);
      strcat(res, t);
      strcat(res, u);
-     free((void *) s);
+     if (dofree)
+         free((void *) s);
      return res;
 }
 
@@ -69,7 +72,9 @@  char *
 xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
      char *res;
 
-     if (!s) s = "";
+     int dofree = 1;
+
+     if (!s) s = "", dofree=0;
      if (!t) t = "";
      if (!u) u = "";
      if (!v) v = "";
@@ -78,7 +83,8 @@  xstrconcat4 (const char *s, const char *t, const char *u, const char *v) {
      strcat(res, t);
      strcat(res, u);
      strcat(res, v);
-     free((void *) s);
+     if (dofree)
+         free((void *) s);
      return res;
 }