1f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine/* $OpenBSD: regfree.c,v 1.7 2005/08/05 13:03:00 espie Exp $ */ 2f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine/*- 3f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * Copyright (c) 1992, 1993, 1994 Henry Spencer. 4f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * Copyright (c) 1992, 1993, 1994 5f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * The Regents of the University of California. All rights reserved. 6f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 7f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * This code is derived from software contributed to Berkeley by 8f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * Henry Spencer. 9f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 10f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * Redistribution and use in source and binary forms, with or without 11f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * modification, are permitted provided that the following conditions 12f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * are met: 13f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 1. Redistributions of source code must retain the above copyright 14f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * notice, this list of conditions and the following disclaimer. 15f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 2. Redistributions in binary form must reproduce the above copyright 16f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * notice, this list of conditions and the following disclaimer in the 17f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * documentation and/or other materials provided with the distribution. 18f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 3. Neither the name of the University nor the names of its contributors 19f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * may be used to endorse or promote products derived from this software 20f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * without specific prior written permission. 21f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 22f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * SUCH DAMAGE. 33f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * 34f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine * @(#)regfree.c 8.3 (Berkeley) 3/20/94 35f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine */ 36f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine 37f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine#include <sys/types.h> 38f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine#include <stdio.h> 39f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine#include <stdlib.h> 40f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine// #include <regex.h> 41f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine#include "./regex.h" 42f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine 43f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine#include "utils.h" 44f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine// #include "regex2.h" 45f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine#include "./regex2.h" 46f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine 47f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine/* 48f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine - regfree - free everything 49f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine */ 50f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkinevoid 51f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkineregfree(regex_t *preg) 52f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine{ 53f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine struct re_guts *g; 54f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine 55f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine if (preg->re_magic != MAGIC1) /* oops */ 56f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine return; /* nice to complain, but hard */ 57f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine 58f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine g = preg->re_g; 59f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine if (g == NULL || g->magic != MAGIC2) /* oops again */ 60f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine return; 61f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine preg->re_magic = 0; /* mark it invalid */ 62f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine g->magic = 0; /* mark it invalid */ 63f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine 64f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine if (g->strip != NULL) 65f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine free((char *)g->strip); 66f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine if (g->sets != NULL) 67f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine free((char *)g->sets); 68f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine if (g->setbits != NULL) 69f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine free((char *)g->setbits); 70f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine if (g->must != NULL) 71f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine free(g->must); 72f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine free((char *)g); 73f9e88edc21c894886747e899dc29c02a28728d65Vladimir Chtchetkine} 74