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