bug-tar
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-tar] [PATCH] wordsplit: avoid leak if WRDSF_ENV


From: Pavel Raiskup
Subject: [Bug-tar] [PATCH] wordsplit: avoid leak if WRDSF_ENV
Date: Fri, 27 Jul 2018 17:24:46 +0200

* lib/wordsplit.c (expvar): Don't copy string returned from
wordsplit_find_env by strdup(), it's not needed and the value is
never freed.
---
 lib/wordsplit.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/lib/wordsplit.c b/lib/wordsplit.c
index f2ecada..a186f2e 100644
--- a/lib/wordsplit.c
+++ b/lib/wordsplit.c
@@ -707,7 +707,6 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
   size_t i = 0;
   const char *defstr = NULL;
   const char *value;
-  const char *vptr;
   struct wordsplit_node *newnode;
   const char *start = str - 1;
 
@@ -770,13 +769,8 @@ expvar (struct wordsplit *wsp, const char *str, size_t len,
      i   - its length
      defstr - default replacement str */
 
-  vptr = wordsplit_find_env (wsp, str, i);
-  if (vptr)
-    {
-      value = strdup (vptr);
-      if (!value)
-       return _wsplt_nomem (wsp);
-    }
+  if ((value = wordsplit_find_env (wsp, str, i)))
+    ; /* returns pointer into wsp->ws_env */
   else if (wsp->ws_flags & WRDSF_GETVAR)
     value = wsp->ws_getvar (str, i, wsp->ws_closure);
   else if (wsp->ws_flags & WRDSF_UNDEF)
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]