Check for NULL pointer before passing it into qsort & free
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 25 May 2012 11:11:36 +0000 (13:11 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Fri, 25 May 2012 11:11:36 +0000 (13:11 +0200)
citadel/modules/fulltext/serv_fulltext.c

index 681262b4e67aa4aca5c99667d61f94bbed35eb29..3fa22d781618b3cb3ba93a13336ee71372daccaf 100644 (file)
@@ -415,7 +415,8 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
 
                }
                free(tokens);
-               qsort(all_msgs, num_all_msgs, sizeof(long), longcmp);
+               if (all_msgs != NULL)
+                       qsort(all_msgs, num_all_msgs, sizeof(long), longcmp);
 
                /*
                 * At this point, if a message appears num_tokens times in the
@@ -435,8 +436,8 @@ void ft_search(int *fts_num_msgs, long **fts_msgs, const char *search_string) {
 
                        }
                }
-
-               free(all_msgs);
+               if (all_msgs != NULL)
+                       free(all_msgs);
        }
 
        *fts_num_msgs = num_ret_msgs;