Fix: segfault in tab completion (RHBZ#516024).
authorRichard Jones <rjones@trick.home.annexia.org>
Thu, 6 Aug 2009 13:35:46 +0000 (14:35 +0100)
committerRichard Jones <rjones@trick.home.annexia.org>
Thu, 6 Aug 2009 14:03:56 +0000 (15:03 +0100)
Actually this fixes two bugs: 'strs' was not being freed on every
path, and the tab completion segfault described in the bug report.

fish/destpaths.c

index f4f1318..8b6173a 100644 (file)
@@ -113,7 +113,7 @@ complete_dest_paths_generator (const char *text, int state)
       size_t i;                                                                \
       size_t n = count_strings (strs);                                 \
                                                                         \
-      if ( ! xalloc_oversized (nr_words + n, sizeof (struct word))) {  \
+      if ( n > 0 && ! xalloc_oversized (nr_words + n, sizeof (struct word))) { \
         struct word *w;                                                        \
         w = realloc (words, sizeof (struct word) * (nr_words + n));    \
                                                                         \
@@ -129,8 +129,8 @@ complete_dest_paths_generator (const char *text, int state)
             nr_words++;                                                        \
           }                                                            \
         }                                                              \
-        free (strs);                                                   \
       }                                                                        \
+      free (strs);                                                     \
     }                                                                  \
   } while (0)