1 /*- 2 * Copyright (c) 1992 Henry Spencer. 3 * Copyright (c) 1992 The Regents of the University of California. 4 * 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 5.1 (Berkeley) 08/06/92 12 */ 13 14 #if defined(LIBC_SCCS) && !defined(lint) 15 static char sccsid[] = "@(#)regfree.c 5.1 (Berkeley) 08/06/92"; 16 #endif /* LIBC_SCCS and not lint */ 17 18 #include <sys/types.h> 19 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <regex.h> 23 24 #include "utils.h" 25 #include "regex2.h" 26 27 /* 28 - regfree - free everything 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((char *)g->must); 53 } 54