new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_regex / os_pcre2_free_pattern.c
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All right reserved.
3  *
4  * This program is a free software; you can redistribute it
5  * and/or modify it under the terms of the GNU General Public
6  * License (version 2) as published by the FSF - Free Software
7  * Foundation
8  */
9
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13
14 #include "os_regex.h"
15
16 /* Release all the memory created by the compilation/execution phases */
17 void OSPcre2_FreePattern(OSPcre2 *reg)
18 {
19     /* Free the match data */
20     if (reg->match_data) {
21         pcre2_match_data_free(reg->match_data);
22         reg->match_data = NULL;
23     }
24
25     /* Free the regex */
26     if (reg->regex) {
27         pcre2_code_free(reg->regex);
28         reg->regex = NULL;
29     }
30
31     /* Free the patter, */
32     if (reg->pattern) {
33         free(reg->pattern);
34         reg->pattern = NULL;
35     }
36
37     /* Free the sub strings */
38     if (reg->sub_strings) {
39         OSPcre2_FreeSubStrings(reg);
40         free(reg->sub_strings);
41         reg->sub_strings = NULL;
42     }
43
44     return;
45 }
46