1*e0b8e63eSJohn Marino /* $NetBSD: regfree.c,v 1.2 2009/01/02 00:32:11 tnozaki Exp $ */
2*e0b8e63eSJohn Marino
3*e0b8e63eSJohn Marino /*-
4*e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994 Henry Spencer.
5*e0b8e63eSJohn Marino * Copyright (c) 1992, 1993, 1994
6*e0b8e63eSJohn Marino * The Regents of the University of California. All rights reserved.
7*e0b8e63eSJohn Marino *
8*e0b8e63eSJohn Marino * This code is derived from software contributed to Berkeley by
9*e0b8e63eSJohn Marino * Henry Spencer of the University of Toronto.
10*e0b8e63eSJohn Marino *
11*e0b8e63eSJohn Marino * Redistribution and use in source and binary forms, with or without
12*e0b8e63eSJohn Marino * modification, are permitted provided that the following conditions
13*e0b8e63eSJohn Marino * are met:
14*e0b8e63eSJohn Marino * 1. Redistributions of source code must retain the above copyright
15*e0b8e63eSJohn Marino * notice, this list of conditions and the following disclaimer.
16*e0b8e63eSJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
17*e0b8e63eSJohn Marino * notice, this list of conditions and the following disclaimer in the
18*e0b8e63eSJohn Marino * documentation and/or other materials provided with the distribution.
19*e0b8e63eSJohn Marino * 3. Neither the name of the University nor the names of its contributors
20*e0b8e63eSJohn Marino * may be used to endorse or promote products derived from this software
21*e0b8e63eSJohn Marino * without specific prior written permission.
22*e0b8e63eSJohn Marino *
23*e0b8e63eSJohn Marino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24*e0b8e63eSJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25*e0b8e63eSJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26*e0b8e63eSJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27*e0b8e63eSJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28*e0b8e63eSJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29*e0b8e63eSJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30*e0b8e63eSJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31*e0b8e63eSJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32*e0b8e63eSJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33*e0b8e63eSJohn Marino * SUCH DAMAGE.
34*e0b8e63eSJohn Marino *
35*e0b8e63eSJohn Marino * @(#)regfree.c 8.2 (Berkeley) 3/16/94
36*e0b8e63eSJohn Marino */
37*e0b8e63eSJohn Marino
38*e0b8e63eSJohn Marino #if defined(LIBC_SCCS) && !defined(lint)
39*e0b8e63eSJohn Marino static char sccsid[] = "@(#)regfree.c 8.2 (Berkeley) 3/16/94";
40*e0b8e63eSJohn Marino #endif /* LIBC_SCCS and not lint */
41*e0b8e63eSJohn Marino
42*e0b8e63eSJohn Marino #include <sys/types.h>
43*e0b8e63eSJohn Marino #include <stdio.h>
44*e0b8e63eSJohn Marino #include <stdlib.h>
45*e0b8e63eSJohn Marino #include <regex.h>
46*e0b8e63eSJohn Marino
47*e0b8e63eSJohn Marino #include "utils.h"
48*e0b8e63eSJohn Marino #include "regex2.h"
49*e0b8e63eSJohn Marino
50*e0b8e63eSJohn Marino /*
51*e0b8e63eSJohn Marino - regfree - free everything
52*e0b8e63eSJohn Marino */
53*e0b8e63eSJohn Marino void
regfree(regex_t * preg)54*e0b8e63eSJohn Marino regfree(regex_t *preg)
55*e0b8e63eSJohn Marino {
56*e0b8e63eSJohn Marino struct re_guts *g;
57*e0b8e63eSJohn Marino
58*e0b8e63eSJohn Marino if (preg->re_magic != MAGIC1) /* oops */
59*e0b8e63eSJohn Marino return; /* nice to complain, but hard */
60*e0b8e63eSJohn Marino
61*e0b8e63eSJohn Marino g = preg->re_g;
62*e0b8e63eSJohn Marino if (g == NULL || g->magic != MAGIC2) /* oops again */
63*e0b8e63eSJohn Marino return;
64*e0b8e63eSJohn Marino preg->re_magic = 0; /* mark it invalid */
65*e0b8e63eSJohn Marino g->magic = 0; /* mark it invalid */
66*e0b8e63eSJohn Marino
67*e0b8e63eSJohn Marino if (g->strip != NULL)
68*e0b8e63eSJohn Marino free((char *)g->strip);
69*e0b8e63eSJohn Marino if (g->stripdata != NULL)
70*e0b8e63eSJohn Marino free((char *)g->stripdata);
71*e0b8e63eSJohn Marino if (g->sets != NULL)
72*e0b8e63eSJohn Marino free((char *)g->sets);
73*e0b8e63eSJohn Marino if (g->setbits != NULL)
74*e0b8e63eSJohn Marino free((char *)g->setbits);
75*e0b8e63eSJohn Marino if (g->must != NULL)
76*e0b8e63eSJohn Marino free(g->must);
77*e0b8e63eSJohn Marino free((char *)g);
78*e0b8e63eSJohn Marino }
79