Imported Upstream version 2.5.1
[debian/amanda] / regex-src / regfree.c
1 #include "amanda.h"
2 #include <regex.h>
3 #include "utils.h"
4 #include "regex2.h"
5
6 /*
7  - regfree - free everything
8  = extern void regfree(regex_t *);
9  */
10 void
11 regfree(
12     regex_t *preg)
13 {
14         register struct re_guts *g;
15
16         /*@ignore@*/
17         if (preg->re_magic != MAGIC1)   /* oops */
18                 return;                 /* nice to complain, but hard */
19
20         g = preg->re_g;
21         if (g == NULL || g->magic != MAGIC2)    /* oops again */
22                 return;
23         preg->re_magic = 0;             /* mark it invalid */
24         /*@end@*/
25         g->magic = 0;                   /* mark it invalid */
26
27         if (g->strip != NULL)
28                 free((char *)g->strip);
29         if (g->sets != NULL)
30                 free((char *)g->sets);
31         if (g->setbits != NULL)
32                 free((char *)g->setbits);
33         if (g->must != NULL)
34                 free(g->must);
35         free((char *)g);
36 }