OSSP CVS Repository

ossp - Check-in [2470]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2470
Date: 2002-Aug-01 17:27:01 (local)
2002-Aug-01 15:27:01 (UTC)
User:thl
Branch:
Comment: use pcre_free()
Tickets:
Inspections:
Files:
ossp-pkg/fsl/fsl.c      1.45 -> 1.46     57 inserted, 42 deleted

ossp-pkg/fsl/fsl.c 1.45 -> 1.46

--- fsl.c        2002/08/01 11:41:05     1.45
+++ fsl.c        2002/08/01 15:27:01     1.46
@@ -429,6 +429,12 @@
     l2_channel_t     *ch; /* scratch variable */
     l2_result_t       l2rv;
     int               matchcount = 0;
+    pcre       *pcreRegex = NULL;
+    pcre_extra *pcreExtra = NULL;
+    const char *cpError;
+    int         iError;
+    int         nMatch;
+
 
     if ((cfg == NULL) || (cpISF == NULL) || (strlen(cpISF) < 3) || (mode < 0) || (mode > 1))
         return FSL_ERR_ARG;
@@ -518,49 +524,50 @@
                   ) {
                 /*  process the directive using the three arguments found */
                 fsldebug(L2_LEVEL_DEBUG, "processcfg: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec);
-                {
-                    pcre       *pcreRegex;
-                    pcre_extra *pcreExtra;
-                    const char *cpError;
-                    int         iError;
-                    int         nMatch;
-
-                    /* compile regular expression into finite state machine and optimize */
-                    if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) {
-                        fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_compile() failed with error %s (%d)", cpError, iError); CU(FSL_ERR_CUS); }
-                    pcreExtra = pcre_study(pcreRegex, 0, &cpError);
-                    if (cpError != NULL) {
-                        fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_study() failed with error %s", cpError); CU(FSL_ERR_CUS); }
-
-                    nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE);
-                    if (nMatch < 0)
-                        fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" failed.", cpISF, argmatch);
+
+                /* compile regular expression into finite state machine and optimize */
+                if ((pcreRegex = pcre_compile(argmatch, PCRE_CASELESS, &cpError, &iError, NULL)) == NULL) {
+                    fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_compile() failed with error %s (%d)", cpError, iError); CU(FSL_ERR_CUS); }
+                pcreExtra = pcre_study(pcreRegex, 0, &cpError);
+                if (cpError != NULL) {
+                    fsldebug(L2_LEVEL_ERROR, "processcfg: pcre_study() failed with error %s", cpError); CU(FSL_ERR_CUS); }
+
+                nMatch = pcre_exec(pcreRegex, pcreExtra, cpISF, strlen(cpISF), 0, 0, ovec, OVECSIZE);
+                if (nMatch < 0)
+                    fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" failed.", cpISF, argmatch);
+                else
+                    if (nMatch == 0)
+                        fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0", cpISF, argmatch);
                     else
-                        if (nMatch == 0)
-                            fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0", cpISF, argmatch);
-                        else
-                            fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1));
-                    if (nMatch >= 1) {
-                        pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch);
-                        if (acpMatch != NULL)
-                            for (i = 0; i < nMatch; i++)
-                                fsldebug(L2_LEVEL_DEBUG, "processcfg: regex reference[%d]=\'%s\'", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]);
-                        n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL);
-                        if ((cp = (char *)malloc(n + 1)) == NULL) {
-                            fsldebug(L2_LEVEL_ERROR, "processcfg: malloc() failed"); CU(FSL_ERR_CUS); }
-                        if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) {
-                            fsldebug(L2_LEVEL_ERROR, "processcfg: substcapture() failed"); CU(FSL_ERR_CUS); }
-                        argl2spec = cp;
-                        fsldebug(L2_LEVEL_DEBUG, "processcfg: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec);
-
-                        /* create L2 channel throuh spec and link into root channel */
-                        if ((l2rv = l2_spec(&ch, ctx.l2_env, "%s", argl2spec)) != L2_OK) {
-                            cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to create stream from spec %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); }
-                        if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) {
-                            cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to link child channel %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); }
-                        matchcount++;
-                        free(argl2spec);
-                    }
+                        fsldebug(L2_LEVEL_TRACE, "processcfg: matching ident/facility \"%s\" against section \"%s\" succeeded, found $0...$%d", cpISF, argmatch, (nMatch-1) > 9 ? 9 : (nMatch-1));
+                if (nMatch >= 1) {
+                    pcre_get_substring_list(cpISF, ovec, nMatch, &acpMatch);
+                    if (acpMatch != NULL)
+                        for (i = 0; i < nMatch; i++)
+                            fsldebug(L2_LEVEL_DEBUG, "processcfg: regex reference[%d]=\'%s\'", i, acpMatch[i] == NULL ? "(UNDEFINED)" : acpMatch[i]);
+                    n = substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, NULL);
+                    if ((cp = (char *)malloc(n + 1)) == NULL) {
+                        fsldebug(L2_LEVEL_ERROR, "processcfg: malloc() failed"); CU(FSL_ERR_CUS); }
+                    if (substcapture(argl2spec, strlen(argl2spec), acpMatch, nMatch, cp) != n) {
+                        fsldebug(L2_LEVEL_ERROR, "processcfg: substcapture() failed"); CU(FSL_ERR_CUS); }
+                    argl2spec = cp;
+                    fsldebug(L2_LEVEL_DEBUG, "processcfg: argident=%s, argmatch=%s, argl2spec=%s", argident, argmatch, argl2spec);
+
+                    /* create L2 channel throuh spec and link into root channel */
+                    if ((l2rv = l2_spec(&ch, ctx.l2_env, "%s", argl2spec)) != L2_OK) {
+                        cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to create stream from spec %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); }
+                    if ((l2rv = l2_channel_link(ctx.l2_nch, L2_LINK_CHILD, ch, NULL)) != L2_OK) {
+                        cp = l2_env_strerror(ctx.l2_env, l2rv); fsldebug(L2_LEVEL_ERROR, "processcfg: logging failed to link child channel %s(%d)", cp, l2rv); CU(FSL_ERR_CUS); }
+                    matchcount++;
+                    free(argl2spec);
+                }
+                if (pcreExtra != NULL) {
+                    pcre_free(pcreExtra);
+                    pcreExtra = NULL;
+                }
+                if (pcreRegex != NULL) {
+                    pcre_free(pcreRegex);
+                    pcreRegex = NULL;
                 }
             }
             else
@@ -605,6 +612,14 @@
     else
         CU(FSL_OK);
 CUS:
+    if (pcreExtra != NULL) {
+        pcre_free(pcreExtra);
+        pcreExtra = NULL;
+    }
+    if (pcreRegex != NULL) {
+        pcre_free(pcreRegex);
+        pcreRegex = NULL;
+    }
     return rc;
 }
 

CVSTrac 2.0.1