From: Ben Pfaff <blp@cs.stanford.edu>
Date: Fri, 9 Apr 2010 04:12:02 +0000 (-0700)
Subject: dictionary: Fix memory leak in dict_set_encoding().
X-Git-Tag: sav-api~325
X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=01900114dde51eecc8adc4933ef52289e37c480f;p=pspp

dictionary: Fix memory leak in dict_set_encoding().

If this function was called more than once for a given dictionary then all
but the final encoding name would be leaked.
---

diff --git a/src/data/dictionary.c b/src/data/dictionary.c
index f69d91e360..bca92dabe3 100644
--- a/src/data/dictionary.c
+++ b/src/data/dictionary.c
@@ -81,7 +81,10 @@ void
 dict_set_encoding (struct dictionary *d, const char *enc)
 {
   if (enc)
-    d->encoding = xstrdup (enc);
+    {
+      free (d->encoding);
+      d->encoding = xstrdup (enc);
+    }
 }
 
 const char *