xref: /csrg-svn/lib/libc/regex/regfree.c (revision 60201)
155852Sbostic /*-
255852Sbostic  * Copyright (c) 1992 Henry Spencer.
355852Sbostic  * Copyright (c) 1992 The Regents of the University of California.
455852Sbostic  * All rights reserved.
555852Sbostic  *
655852Sbostic  * This code is derived from software contributed to Berkeley by
755852Sbostic  * Henry Spencer of the University of Toronto.
855852Sbostic  *
955852Sbostic  * %sccs.include.redist.c%
1055852Sbostic  *
11*60201Sbostic  *	@(#)regfree.c	5.2 (Berkeley) 05/21/93
1255852Sbostic  */
1355852Sbostic 
1455852Sbostic #if defined(LIBC_SCCS) && !defined(lint)
15*60201Sbostic static char sccsid[] = "@(#)regfree.c	5.2 (Berkeley) 05/21/93";
1655852Sbostic #endif /* LIBC_SCCS and not lint */
1755852Sbostic 
1855852Sbostic #include <sys/types.h>
1955852Sbostic #include <stdio.h>
2055852Sbostic #include <stdlib.h>
2155852Sbostic #include <regex.h>
2255852Sbostic 
2355852Sbostic #include "utils.h"
2455852Sbostic #include "regex2.h"
2555852Sbostic 
2655852Sbostic /*
2755852Sbostic  - regfree - free everything
28*60201Sbostic  = extern void regfree(regex_t *preg);
2955852Sbostic  */
3055852Sbostic void
3155852Sbostic regfree(preg)
3255852Sbostic regex_t *preg;
3355852Sbostic {
3455852Sbostic 	register struct re_guts *g;
3555852Sbostic 
3655852Sbostic 	if (preg->re_magic != MAGIC1)	/* oops */
3755852Sbostic 		return;			/* nice to complain, but hard */
3855852Sbostic 
3955852Sbostic 	g = preg->re_g;
4055852Sbostic 	if (g == NULL || g->magic != MAGIC2)	/* oops again */
4155852Sbostic 		return;
4255852Sbostic 	preg->re_magic = 0;		/* mark it invalid */
4355852Sbostic 	g->magic = 0;			/* mark it invalid */
4455852Sbostic 
4555852Sbostic 	if (g->strip != NULL)
4655852Sbostic 		free((char *)g->strip);
4755852Sbostic 	if (g->sets != NULL)
4855852Sbostic 		free((char *)g->sets);
4955852Sbostic 	if (g->setbits != NULL)
5055852Sbostic 		free((char *)g->setbits);
5155852Sbostic 	if (g->must != NULL)
52*60201Sbostic 		free(g->must);
53*60201Sbostic 	free((char *)g);
5455852Sbostic }
55