Back to index

php5  5.3.10
regfree.c
Go to the documentation of this file.
00001 #include <sys/types.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 
00005 #include "regex.h"
00006 #include "utils.h"
00007 #include "regex2.h"
00008 
00009 /*
00010  - regfree - free everything
00011  = API_EXPORT(void) regfree(regex_t *);
00012  */
00013 API_EXPORT(void)
00014 regfree(preg)
00015 regex_t *preg;
00016 {
00017        register struct re_guts *g;
00018 
00019        if (preg->re_magic != MAGIC1)      /* oops */
00020               return;                     /* nice to complain, but hard */
00021 
00022        g = preg->re_g;
00023        if (g == NULL || g->magic != MAGIC2)      /* oops again */
00024               return;
00025        preg->re_magic = 0;         /* mark it invalid */
00026        g->magic = 0;               /* mark it invalid */
00027 
00028        if (g->strip != NULL)
00029               free((char *)g->strip);
00030        if (g->sets != NULL)
00031               free((char *)g->sets);
00032        if (g->setbits != NULL)
00033               free((char *)g->setbits);
00034        if (g->must != NULL)
00035               free(g->must);
00036        free((char *)g);
00037 }