1254225Speter/* $NetBSD: regfree.c,v 1.2 2009/01/02 00:32:11 tnozaki Exp $ */ 2254225Speter 3254225Speter/*- 4254225Speter * Copyright (c) 1992, 1993, 1994 Henry Spencer. 5254225Speter * Copyright (c) 1992, 1993, 1994 6254225Speter * The Regents of the University of California. All rights reserved. 7254225Speter * 8254225Speter * This code is derived from software contributed to Berkeley by 9254225Speter * Henry Spencer of the University of Toronto. 10254225Speter * 11254225Speter * Redistribution and use in source and binary forms, with or without 12254225Speter * modification, are permitted provided that the following conditions 13254225Speter * are met: 14254225Speter * 1. Redistributions of source code must retain the above copyright 15254225Speter * notice, this list of conditions and the following disclaimer. 16254225Speter * 2. Redistributions in binary form must reproduce the above copyright 17254225Speter * notice, this list of conditions and the following disclaimer in the 18254225Speter * documentation and/or other materials provided with the distribution. 19254225Speter * 3. All advertising materials mentioning features or use of this software 20254225Speter * must display the following acknowledgement: 21254225Speter * This product includes software developed by the University of 22254225Speter * California, Berkeley and its contributors. 23254225Speter * 4. Neither the name of the University nor the names of its contributors 24254225Speter * may be used to endorse or promote products derived from this software 25254225Speter * without specific prior written permission. 26254225Speter * 27254225Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 28254225Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 29254225Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 30254225Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 31254225Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 32254225Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 33254225Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 34254225Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 35254225Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 36254225Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 37254225Speter * SUCH DAMAGE. 38254225Speter * 39254225Speter * @(#)regfree.c 8.2 (Berkeley) 3/16/94 40254225Speter */ 41254225Speter 42254225Speter#if defined(LIBC_SCCS) && !defined(lint) 43254225Speterstatic char sccsid[] = "@(#)regfree.c 8.2 (Berkeley) 3/16/94"; 44254225Speter#endif /* LIBC_SCCS and not lint */ 45254225Speter 46254225Speter#include <sys/types.h> 47254225Speter#include <stdio.h> 48254225Speter#include <stdlib.h> 49254225Speter#include <regex.h> 50254225Speter 51254225Speter#include "utils.h" 52254225Speter#include "regex2.h" 53254225Speter 54254225Speter/* 55254225Speter - regfree - free everything 56254225Speter = extern void regfree(regex_t *); 57254225Speter */ 58254225Spetervoid 59254225Speterregfree(regex_t *preg) 60254225Speter{ 61254225Speter register struct re_guts *g; 62254225Speter 63254225Speter if (preg->re_magic != MAGIC1) /* oops */ 64254225Speter return; /* nice to complain, but hard */ 65254225Speter 66254225Speter g = preg->re_g; 67254225Speter if (g == NULL || g->magic != MAGIC2) /* oops again */ 68254225Speter return; 69254225Speter preg->re_magic = 0; /* mark it invalid */ 70254225Speter g->magic = 0; /* mark it invalid */ 71254225Speter 72254225Speter if (g->strip != NULL) 73254225Speter free((char *)g->strip); 74254225Speter if (g->stripdata != NULL) 75254225Speter free((char *)g->stripdata); 76254225Speter if (g->sets != NULL) 77254225Speter free((char *)g->sets); 78254225Speter if (g->setbits != NULL) 79254225Speter free((char *)g->setbits); 80254225Speter if (g->must != NULL) 81254225Speter free(g->must); 82254225Speter free((char *)g); 83254225Speter} 84