Pavel Raiskup 94b4cd
From a0cab23332a254e3500cac2a3a984472d02180e5 Mon Sep 17 00:00:00 2001
Pavel Raiskup 94b4cd
From: Bruno Haible <bruno@clisp.org>
Pavel Raiskup 94b4cd
Date: Fri, 9 Dec 2016 21:04:31 +0100
Pavel Raiskup 94b4cd
Subject: [PATCH] Fix crash of xgettext with --its option.
Pavel Raiskup 94b4cd
Pavel Raiskup 94b4cd
* gettext-tools/src/xgettext.c (main): Free contents of its_dirs only when it
Pavel Raiskup 94b4cd
was initialized. Fixes bug introduced on 2016-05-16.
Pavel Raiskup 94b4cd
---
Pavel Raiskup 94b4cd
 gettext-tools/src/xgettext.c | 11 +++++++----
Pavel Raiskup 94b4cd
 1 file changed, 7 insertions(+), 4 deletions(-)
Pavel Raiskup 94b4cd
Pavel Raiskup 94b4cd
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
Pavel Raiskup 94b4cd
index f848d76d1..a80ee51ac 100644
Pavel Raiskup 94b4cd
--- a/gettext-tools/src/xgettext.c
Pavel Raiskup 94b4cd
+++ b/gettext-tools/src/xgettext.c
Pavel Raiskup 94b4cd
@@ -330,7 +330,7 @@ main (int argc, char *argv[])
Pavel Raiskup 94b4cd
   bool sort_by_msgid = false;
Pavel Raiskup 94b4cd
   bool sort_by_filepos = false;
Pavel Raiskup 94b4cd
   char **dirs;
Pavel Raiskup 94b4cd
-  char **its_dirs;
Pavel Raiskup 94b4cd
+  char **its_dirs = NULL;
Pavel Raiskup 94b4cd
   char *explicit_its_filename = NULL;
Pavel Raiskup 94b4cd
   const char *file_name;
Pavel Raiskup 94b4cd
   const char *files_from = NULL;
Pavel Raiskup 94b4cd
@@ -1016,9 +1016,12 @@ warning: file '%s' extension '%s' is unknown; will try C"), filename, extension)
Pavel Raiskup 94b4cd
   if (its_locating_rules)
Pavel Raiskup 94b4cd
     locating_rule_list_free (its_locating_rules);
Pavel Raiskup 94b4cd
 
Pavel Raiskup 94b4cd
-  for (i = 0; its_dirs[i] != NULL; i++)
Pavel Raiskup 94b4cd
-    free (its_dirs[i]);
Pavel Raiskup 94b4cd
-  free (its_dirs);
Pavel Raiskup 94b4cd
+  if (its_dirs != NULL)
Pavel Raiskup 94b4cd
+    {
Pavel Raiskup 94b4cd
+      for (i = 0; its_dirs[i] != NULL; i++)
Pavel Raiskup 94b4cd
+        free (its_dirs[i]);
Pavel Raiskup 94b4cd
+      free (its_dirs);
Pavel Raiskup 94b4cd
+    }
Pavel Raiskup 94b4cd
 
Pavel Raiskup 94b4cd
   exit (EXIT_SUCCESS);
Pavel Raiskup 94b4cd
 }
Pavel Raiskup 94b4cd
-- 
Pavel Raiskup 94b4cd
2.14.3
Pavel Raiskup 94b4cd