regfree.c revision 62817
150472Speter/*- 237Srgrimes * Copyright (c) 1992, 1993, 1994 Henry Spencer. 337Srgrimes * Copyright (c) 1992, 1993, 1994 437Srgrimes * The Regents of the University of California. All rights reserved. 527086Swosch * 637Srgrimes * This code is derived from software contributed to Berkeley by 737Srgrimes * Henry Spencer. 837Srgrimes * 937Srgrimes * Redistribution and use in source and binary forms, with or without 1037Srgrimes * modification, are permitted provided that the following conditions 1127086Swosch * are met: 1299134Smaxim * 1. Redistributions of source code must retain the above copyright 1327086Swosch * notice, this list of conditions and the following disclaimer. 14190304Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright 1537Srgrimes * notice, this list of conditions and the following disclaimer in the 1699134Smaxim * documentation and/or other materials provided with the distribution. 1788684Sgshapiro * 3. All advertising materials mentioning features or use of this software 1888684Sgshapiro * must display the following acknowledgement: 1927086Swosch * This product includes software developed by the University of 2040855Sphk * California, Berkeley and its contributors. 2140855Sphk * 4. Neither the name of the University nor the names of its contributors 2237Srgrimes * may be used to endorse or promote products derived from this software 2337Srgrimes * without specific prior written permission. 2437Srgrimes * 2537Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2637Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 27147069Smaxim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 28131343Smaxim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 29243752Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3037Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3169191Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3237Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3337Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 34218119Smaxim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3569191Sdougb * SUCH DAMAGE. 3687664Sgshapiro * 3727086Swosch * @(#)regfree.c 8.3 (Berkeley) 3/20/94 3827086Swosch * 3937Srgrimes * $FreeBSD: head/lib/libc/regex/regfree.c 62817 2000-07-08 09:45:17Z dcs $ 4027086Swosch */ 4143781Sdes 42127234Smaxim#if defined(LIBC_SCCS) && !defined(lint) 4387664Sgshapirostatic char sccsid[] = "@(#)regfree.c 8.3 (Berkeley) 3/20/94"; 4499133Smaxim#endif /* LIBC_SCCS and not lint */ 4537Srgrimes 4637Srgrimes#include <sys/types.h> 4769191Sdougb#include <stdio.h> 4827086Swosch#include <stdlib.h> 4937Srgrimes#include <limits.h> 5037Srgrimes#include <regex.h> 51153Srgrimes 52153Srgrimes#include "utils.h" 53153Srgrimes#include "regex2.h" 5412389Sache 5527086Swosch/* 5627086Swosch - regfree - free everything 5727086Swosch = extern void regfree(regex_t *); 5827086Swosch */ 5927086Swoschvoid 6027086Swoschregfree(preg) 6127086Swoschregex_t *preg; 6228428Swosch{ 6327086Swosch register struct re_guts *g; 6428428Swosch 6527086Swosch if (preg->re_magic != MAGIC1) /* oops */ 6627086Swosch return; /* nice to complain, but hard */ 6728428Swosch 6828428Swosch g = preg->re_g; 6927086Swosch if (g == NULL || g->magic != MAGIC2) /* oops again */ 7027086Swosch return; 7127086Swosch preg->re_magic = 0; /* mark it invalid */ 7227086Swosch g->magic = 0; /* mark it invalid */ 73110551Sgshapiro 74112573Sgshapiro if (g->strip != NULL) 75110551Sgshapiro free((char *)g->strip); 7612389Sache if (g->sets != NULL) 77110551Sgshapiro free((char *)g->sets); 7827086Swosch if (g->setbits != NULL) 7927086Swosch free((char *)g->setbits); 80 if (g->must != NULL) 81 free(g->must); 82 if (g->charjump != NULL) 83 free(&g->charjump[CHAR_MIN]); 84 if (g->matchjump != NULL) 85 free(g->matchjump); 86 free((char *)g); 87} 88