xref: /original-bsd/lib/libc/regex/regfree.c (revision a8f82b20)
1 /*-
2  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
3  * Copyright (c) 1992, 1993, 1994
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Henry Spencer of the University of Toronto.
8  *
9  * %sccs.include.redist.c%
10  *
11  *	@(#)regfree.c	8.2 (Berkeley) 03/16/94
12  */
13 
14 #if defined(LIBC_SCCS) && !defined(lint)
15 static char sccsid[] = "@(#)regfree.c	8.2 (Berkeley) 03/16/94";
16 #endif /* LIBC_SCCS and not lint */
17 
18 #include <sys/types.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <regex.h>
22 
23 #include "utils.h"
24 #include "regex2.h"
25 
26 /*
27  - regfree - free everything
28  = extern void regfree(regex_t *);
29  */
30 void
31 regfree(preg)
32 regex_t *preg;
33 {
34 	register struct re_guts *g;
35 
36 	if (preg->re_magic != MAGIC1)	/* oops */
37 		return;			/* nice to complain, but hard */
38 
39 	g = preg->re_g;
40 	if (g == NULL || g->magic != MAGIC2)	/* oops again */
41 		return;
42 	preg->re_magic = 0;		/* mark it invalid */
43 	g->magic = 0;			/* mark it invalid */
44 
45 	if (g->strip != NULL)
46 		free((char *)g->strip);
47 	if (g->sets != NULL)
48 		free((char *)g->sets);
49 	if (g->setbits != NULL)
50 		free((char *)g->setbits);
51 	if (g->must != NULL)
52 		free(g->must);
53 	free((char *)g);
54 }
55