Also, note the "free(dupfilter)" line which must be added within the
patch at the point marked "HERE>>>":

> +#define FILTER_LIST_INCREMENT        8
> +#define MEMORY_ERROR "432 Out of memory when processing mail filters.\n"
> +
> +static char **filterlist   = NULL;
> +static int  filterlistsize = 0;
> +static int  nfilters    = 0;
> +
> +static void free_filters()
> +{
> +     if (filterlist != NULL)
> +     {
> +             for (int n = 0; n < nfilters; n++)
> +             {
> +                     free(filterlist[n]);
> +             }
> +     }
> +     nfilters = 0;
> +}
> +
> +static int add_filter(const char *filter)
> +{
> +char *dupfilter = strdup(filter);
> +
> +     if (dupfilter == NULL)
> +     {
> +             cout << MEMORY_ERROR << flush;
> +             return (1);
> +     }
> +
> +     if (nfilters >= filterlistsize)
> +     {
> +             if (filterlist == NULL)
> +             {
> +                     filterlist = (char **) malloc(sizeof (char *) *
> +                                                   FILTER_LIST_INCREMENT);
> +             }
> +             else
> +             {
> +                     filterlist = (char **) realloc(filterlist,
> +                                                    sizeof (char *) *
> +                                                    (filterlistsize +
> +                                                     FILTER_LIST_INCREMENT));
> +             }
> +             if (filterlist == NULL)
> +             {
HERE>>>                 free(dupfilter);
> +                     cout << MEMORY_ERROR << flush;
> +                     return (1);
> +             }
> +             filterlistsize += FILTER_LIST_INCREMENT;
> +     }
> +
> +     filterlist[nfilters++] = dupfilter;
> +     return (0);
> +}
> +
>  int run_filter(const char *filename,
>       unsigned nmsgids,
> @@ -40,4 +96,5 @@
>       if (!iswhitelisted)
>       {
> +             free_filters();
>               dirp=opendir(FILTERSOCKETDIR);
>               while (dirp && (de=readdir(dirp)) != 0)
> @@ -47,16 +104,29 @@
>                       sockname = FILTERSOCKETDIR "/";
>                       sockname += de->d_name;
> -                     if (dofilter( sockname,
> -                                     filename, nmsgids,
> -                                     msgidfunc,
> -                                     funcarg))
> +                     if (add_filter(sockname) != 0)
>                       {
> -                             closedir(dirp);
>                               return (1);
>                       }
>               }
>               if (dirp)       closedir(dirp);
> +
> +             qsort((void *) filterlist,
> +                   (size_t) nfilters,
> +                   sizeof (char *),
> +                   (int (*)(const void*, const void*)) strcmp);
> +
> +             for (int n = 0; n < nfilters; n++)
> +             {
> +                     if (dofilter( filterlist[n],
> +                                   filename, nmsgids,
> +                                   msgidfunc,
> +                                   funcarg))
> +                     {
> +                             return (1);
> +                     }
> +             }
>       }
>  
> +     free_filters();
>       dirp=opendir(ALLFILTERSOCKETDIR);
>       while (dirp && (de=readdir(dirp)) != 0)
> @@ -66,14 +136,27 @@
>               sockname = ALLFILTERSOCKETDIR "/";
>               sockname += de->d_name;
> -             if (dofilter( sockname,
> -                             filename, nmsgids,
> -                             msgidfunc,
> -                             funcarg))
> +             if (add_filter(sockname) != 0)
>               {
> -                     closedir(dirp);
>                       return (1);
>               }
>       }
>       if (dirp)       closedir(dirp);
> +
> +     qsort((void *) filterlist,
> +           (size_t) nfilters,
> +           sizeof (char *),
> +           (int (*)(const void*, const void*)) strcmp);
> +
> +     for (int n = 0; n < nfilters; n++)
> +     {
> +             if (dofilter( filterlist[n],
> +                           filename, nmsgids,
> +                           msgidfunc,
> +                           funcarg))
> +             {
> +                     return (1);
> +             }
> +     }
> +
>       return (0);
>  }
> @@ -188,5 +271,5 @@
>       if (isdigit(d))
>       {
> -             if (d != '4' && d != '5')
> +             if (d != '0' && d != '4' && d != '5')
>               {
>                       while (isdigit(sockname[0]) &&
> @@ -204,4 +287,8 @@
>       }
>  
> +     if ('d' == '0')
> +     {
> +             sockname[0] = '2';
> +     }
>       cout << sockname << "\n";

-- 
 Lloyd Zusman
 [EMAIL PROTECTED]
 God bless you.



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users

Reply via email to