Imported Upstream version 2.7
[ossec-hids.git] / src / os_regex / os_regex_free_pattern.c
1 /*   $OSSEC, os_regex_free_pattern.c, v0.1, 2006/01/02, Daniel B. Cid$   */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All right reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16
17 #include "os_regex.h"
18 #include "os_regex_internal.h"
19
20
21 /** int OSRegex_FreePattern(SRegex *reg) v0.1
22  * Release all the memory created by the compilation/executation
23  * phases.
24  * Returns void.
25  */
26 void OSRegex_FreePattern(OSRegex *reg)
27 {
28     int i = 0;
29
30     /* Freeing the patterns */
31     if(reg->patterns)
32     {
33         char **pattern = reg->patterns;
34         while(*pattern)
35         {
36             if(*pattern)
37                 free(*pattern);
38             pattern++;
39         }
40
41         free(reg->patterns);
42         free(reg->flags);
43
44         reg->patterns = NULL;
45         reg->flags = NULL;
46     }
47
48     /* Freeing the closure */
49     if(reg->prts_closure)
50     {
51         i = 0;
52         while(reg->prts_closure[i])
53         {
54             free(reg->prts_closure[i]);
55             i++;
56         }
57         free(reg->prts_closure);
58         reg->prts_closure = NULL;
59     }
60
61     /* Freeing the str */
62     if(reg->prts_str)
63     {
64         i = 0;
65         while(reg->prts_str[i])
66         {
67             free(reg->prts_str[i]);
68             i++;
69         }
70         free(reg->prts_str);
71         reg->prts_str = NULL;
72     }
73
74     /* Freeing the sub strings */
75     if(reg->sub_strings)
76     {
77         OSRegex_FreeSubStrings(reg);
78         free(reg->sub_strings);
79         reg->sub_strings = NULL;
80     }
81
82     return;
83 }
84
85
86 /* EOF */