izmjene licence
[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         reg->patterns = NULL;
43     }
44
45     /* Freeing the flags */
46     free(reg->flags);
47     reg->flags = NULL;
48
49     /* Freeing the closure */
50     if(reg->prts_closure)
51     {
52         i = 0;
53         while(reg->prts_closure[i])
54         {
55             free(reg->prts_closure[i]);
56             i++;
57         }
58         free(reg->prts_closure);
59         reg->prts_closure = NULL;
60     }
61
62     /* Freeing the str */
63     if(reg->prts_str)
64     {
65         i = 0;
66         while(reg->prts_str[i])
67         {
68             free(reg->prts_str[i]);
69             i++;
70         }
71         free(reg->prts_str);
72         reg->prts_str = NULL;
73     }
74
75     /* Freeing the sub strings */
76     if(reg->sub_strings)
77     {
78         OSRegex_FreeSubStrings(reg);
79         free(reg->sub_strings);
80         reg->sub_strings = NULL;
81     }
82
83     return;
84 }
85
86
87 /* EOF */