1198090Srdivacky/*-
2198090Srdivacky * This code is derived from OpenBSD's libc/regex, original license follows:
3198090Srdivacky *
4198090Srdivacky * Copyright (c) 1992, 1993, 1994 Henry Spencer.
5198090Srdivacky * Copyright (c) 1992, 1993, 1994
6198090Srdivacky *	The Regents of the University of California.  All rights reserved.
7198090Srdivacky *
8198090Srdivacky * This code is derived from software contributed to Berkeley by
9198090Srdivacky * Henry Spencer.
10198090Srdivacky *
11198090Srdivacky * Redistribution and use in source and binary forms, with or without
12198090Srdivacky * modification, are permitted provided that the following conditions
13198090Srdivacky * are met:
14198090Srdivacky * 1. Redistributions of source code must retain the above copyright
15198090Srdivacky *    notice, this list of conditions and the following disclaimer.
16198090Srdivacky * 2. Redistributions in binary form must reproduce the above copyright
17198090Srdivacky *    notice, this list of conditions and the following disclaimer in the
18198090Srdivacky *    documentation and/or other materials provided with the distribution.
19198090Srdivacky * 3. Neither the name of the University nor the names of its contributors
20198090Srdivacky *    may be used to endorse or promote products derived from this software
21198090Srdivacky *    without specific prior written permission.
22198090Srdivacky *
23198090Srdivacky * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24198090Srdivacky * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25198090Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26198090Srdivacky * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27198090Srdivacky * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28198090Srdivacky * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29198090Srdivacky * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30198090Srdivacky * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31198090Srdivacky * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32198090Srdivacky * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33198090Srdivacky * SUCH DAMAGE.
34198090Srdivacky *
35198090Srdivacky *	@(#)regfree.c	8.3 (Berkeley) 3/20/94
36198090Srdivacky */
37198090Srdivacky
38198090Srdivacky#include <sys/types.h>
39198090Srdivacky#include <stdio.h>
40198090Srdivacky#include <stdlib.h>
41198090Srdivacky#include "regex_impl.h"
42198090Srdivacky
43198090Srdivacky#include "regutils.h"
44198090Srdivacky#include "regex2.h"
45198090Srdivacky
46198090Srdivacky/*
47198090Srdivacky - llvm_regfree - free everything
48198090Srdivacky */
49198090Srdivackyvoid
50198090Srdivackyllvm_regfree(llvm_regex_t *preg)
51198090Srdivacky{
52198090Srdivacky	struct re_guts *g;
53198090Srdivacky
54198090Srdivacky	if (preg->re_magic != MAGIC1)	/* oops */
55198090Srdivacky		return;			/* nice to complain, but hard */
56198090Srdivacky
57198090Srdivacky	g = preg->re_g;
58198090Srdivacky	if (g == NULL || g->magic != MAGIC2)	/* oops again */
59198090Srdivacky		return;
60198090Srdivacky	preg->re_magic = 0;		/* mark it invalid */
61198090Srdivacky	g->magic = 0;			/* mark it invalid */
62198090Srdivacky
63198090Srdivacky	if (g->strip != NULL)
64198090Srdivacky		free((char *)g->strip);
65198090Srdivacky	if (g->sets != NULL)
66198090Srdivacky		free((char *)g->sets);
67198090Srdivacky	if (g->setbits != NULL)
68198090Srdivacky		free((char *)g->setbits);
69198090Srdivacky	if (g->must != NULL)
70198090Srdivacky		free(g->must);
71198090Srdivacky	free((char *)g);
72198090Srdivacky}
73