Commit | Line | Data |
---|---|---|
93ea669f KB |
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 | * | |
6175ca7c | 11 | * @(#)regfree.c 5.2 (Berkeley) %G% |
93ea669f KB |
12 | */ |
13 | ||
14 | #if defined(LIBC_SCCS) && !defined(lint) | |
6175ca7c | 15 | static char sccsid[] = "@(#)regfree.c 5.2 (Berkeley) %G%"; |
93ea669f KB |
16 | #endif /* LIBC_SCCS and not lint */ |
17 | ||
18 | #include <sys/types.h> | |
93ea669f KB |
19 | #include <stdio.h> |
20 | #include <stdlib.h> | |
21 | #include <regex.h> | |
22 | ||
23 | #include "utils.h" | |
24 | #include "regex2.h" | |
25 | ||
26 | /* | |
27 | - regfree - free everything | |
6175ca7c | 28 | = extern void regfree(regex_t *preg); |
93ea669f KB |
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) | |
6175ca7c KB |
52 | free(g->must); |
53 | free((char *)g); | |
93ea669f | 54 | } |