1*2fe8fb19SBen Gras /* $NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $ */
2*2fe8fb19SBen Gras
3b7061124SArun Thomas /*-
4b7061124SArun Thomas * Copyright (c) 1992, 1993, 1994
5b7061124SArun Thomas * The Regents of the University of California. All rights reserved.
6b7061124SArun Thomas *
7b7061124SArun Thomas * This code is derived from software contributed to Berkeley by
8b7061124SArun Thomas * Henry Spencer.
9b7061124SArun Thomas *
10b7061124SArun Thomas * Redistribution and use in source and binary forms, with or without
11b7061124SArun Thomas * modification, are permitted provided that the following conditions
12b7061124SArun Thomas * are met:
13b7061124SArun Thomas * 1. Redistributions of source code must retain the above copyright
14b7061124SArun Thomas * notice, this list of conditions and the following disclaimer.
15b7061124SArun Thomas * 2. Redistributions in binary form must reproduce the above copyright
16b7061124SArun Thomas * notice, this list of conditions and the following disclaimer in the
17b7061124SArun Thomas * documentation and/or other materials provided with the distribution.
18*2fe8fb19SBen Gras * 3. Neither the name of the University nor the names of its contributors
19*2fe8fb19SBen Gras * may be used to endorse or promote products derived from this software
20*2fe8fb19SBen Gras * without specific prior written permission.
21*2fe8fb19SBen Gras *
22*2fe8fb19SBen Gras * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*2fe8fb19SBen Gras * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*2fe8fb19SBen Gras * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*2fe8fb19SBen Gras * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*2fe8fb19SBen Gras * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*2fe8fb19SBen Gras * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*2fe8fb19SBen Gras * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*2fe8fb19SBen Gras * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*2fe8fb19SBen Gras * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*2fe8fb19SBen Gras * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*2fe8fb19SBen Gras * SUCH DAMAGE.
33*2fe8fb19SBen Gras *
34*2fe8fb19SBen Gras * @(#)regfree.c 8.3 (Berkeley) 3/20/94
35*2fe8fb19SBen Gras */
36*2fe8fb19SBen Gras
37*2fe8fb19SBen Gras /*-
38*2fe8fb19SBen Gras * Copyright (c) 1992, 1993, 1994 Henry Spencer.
39*2fe8fb19SBen Gras *
40*2fe8fb19SBen Gras * This code is derived from software contributed to Berkeley by
41*2fe8fb19SBen Gras * Henry Spencer.
42*2fe8fb19SBen Gras *
43*2fe8fb19SBen Gras * Redistribution and use in source and binary forms, with or without
44*2fe8fb19SBen Gras * modification, are permitted provided that the following conditions
45*2fe8fb19SBen Gras * are met:
46*2fe8fb19SBen Gras * 1. Redistributions of source code must retain the above copyright
47*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer.
48*2fe8fb19SBen Gras * 2. Redistributions in binary form must reproduce the above copyright
49*2fe8fb19SBen Gras * notice, this list of conditions and the following disclaimer in the
50*2fe8fb19SBen Gras * documentation and/or other materials provided with the distribution.
51b7061124SArun Thomas * 3. All advertising materials mentioning features or use of this software
52b7061124SArun Thomas * must display the following acknowledgement:
53b7061124SArun Thomas * This product includes software developed by the University of
54b7061124SArun Thomas * California, Berkeley and its contributors.
55b7061124SArun Thomas * 4. Neither the name of the University nor the names of its contributors
56b7061124SArun Thomas * may be used to endorse or promote products derived from this software
57b7061124SArun Thomas * without specific prior written permission.
58b7061124SArun Thomas *
59b7061124SArun Thomas * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60b7061124SArun Thomas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61b7061124SArun Thomas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62b7061124SArun Thomas * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63b7061124SArun Thomas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64b7061124SArun Thomas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65b7061124SArun Thomas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66b7061124SArun Thomas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67b7061124SArun Thomas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68b7061124SArun Thomas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69b7061124SArun Thomas * SUCH DAMAGE.
70b7061124SArun Thomas *
71b7061124SArun Thomas * @(#)regfree.c 8.3 (Berkeley) 3/20/94
72b7061124SArun Thomas */
73b7061124SArun Thomas
74*2fe8fb19SBen Gras #include <sys/cdefs.h>
75b7061124SArun Thomas #if defined(LIBC_SCCS) && !defined(lint)
76*2fe8fb19SBen Gras #if 0
77b7061124SArun Thomas static char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94";
78*2fe8fb19SBen Gras #else
79*2fe8fb19SBen Gras __RCSID("$NetBSD: regfree.c,v 1.15 2007/02/09 23:44:18 junyoung Exp $");
80*2fe8fb19SBen Gras #endif
81b7061124SArun Thomas #endif /* LIBC_SCCS and not lint */
82b7061124SArun Thomas
83*2fe8fb19SBen Gras #include "namespace.h"
84b7061124SArun Thomas #include <sys/types.h>
85*2fe8fb19SBen Gras
86*2fe8fb19SBen Gras #include <assert.h>
87b7061124SArun Thomas #include <stdio.h>
88b7061124SArun Thomas #include <stdlib.h>
89b7061124SArun Thomas #include <regex.h>
90b7061124SArun Thomas
91*2fe8fb19SBen Gras #ifdef __weak_alias
__weak_alias(regfree,_regfree)92*2fe8fb19SBen Gras __weak_alias(regfree,_regfree)
93*2fe8fb19SBen Gras #endif
94*2fe8fb19SBen Gras
95b7061124SArun Thomas #include "utils.h"
96b7061124SArun Thomas #include "regex2.h"
97b7061124SArun Thomas
98b7061124SArun Thomas /*
99b7061124SArun Thomas - regfree - free everything
100b7061124SArun Thomas = extern void regfree(regex_t *);
101b7061124SArun Thomas */
102b7061124SArun Thomas void
103*2fe8fb19SBen Gras regfree(
104*2fe8fb19SBen Gras regex_t *preg)
105b7061124SArun Thomas {
106*2fe8fb19SBen Gras struct re_guts *g;
107b7061124SArun Thomas
108*2fe8fb19SBen Gras _DIAGASSERT(preg != NULL);
109*2fe8fb19SBen Gras
110*2fe8fb19SBen Gras _DIAGASSERT(preg->re_magic == MAGIC1);
111b7061124SArun Thomas if (preg->re_magic != MAGIC1) /* oops */
112b7061124SArun Thomas return; /* nice to complain, but hard */
113b7061124SArun Thomas
114b7061124SArun Thomas g = preg->re_g;
115b7061124SArun Thomas if (g == NULL || g->magic != MAGIC2) /* oops again */
116b7061124SArun Thomas return;
117b7061124SArun Thomas preg->re_magic = 0; /* mark it invalid */
118b7061124SArun Thomas g->magic = 0; /* mark it invalid */
119b7061124SArun Thomas
120b7061124SArun Thomas if (g->strip != NULL)
121*2fe8fb19SBen Gras free(g->strip);
122b7061124SArun Thomas if (g->sets != NULL)
123*2fe8fb19SBen Gras free(g->sets);
124b7061124SArun Thomas if (g->setbits != NULL)
125*2fe8fb19SBen Gras free(g->setbits);
126b7061124SArun Thomas if (g->must != NULL)
127b7061124SArun Thomas free(g->must);
128*2fe8fb19SBen Gras free(g);
129b7061124SArun Thomas }
130