changeset 35459:a5db73d46825

(xfree): New function. (member, declaration, globals): Use xmalloc instead of alloca.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 22 Jan 2001 11:52:45 +0000
parents 52a68daf83b8
children fdc935c7dceb
files lib-src/ebrowse.c
diffstat 1 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/lib-src/ebrowse.c	Mon Jan 22 11:23:38 2001 +0000
+++ b/lib-src/ebrowse.c	Mon Jan 22 11:52:45 2001 +0000
@@ -478,6 +478,7 @@
 			  unsigned, int, int, int, int));
 void dump_roots P_ ((FILE *));
 void *xmalloc P_ ((int));
+void xfree P_ ((void *));
 void add_global_defn P_ ((char *, char *, int, unsigned, int, int, int));
 void add_global_decl P_ ((char *, char *, int, unsigned, int, int, int));
 void add_define P_ ((char *, char *, int));
@@ -571,6 +572,17 @@
 }
 
 
+/* Like free but always check for null pointers..  */
+
+void
+xfree (p)
+     void *p;
+{
+  if (p)
+    free (p);
+}
+
+
 /* Like strdup, but print an error and exit if not enough memory is
    available..  If S is null, return null.  */
 
@@ -2572,9 +2584,9 @@
           break;
 
         case IDENT:
-          /* Remember IDENTS seen so far.  Among these will be the member
-             name.  */
-	  id = (char *) alloca (strlen (yytext) + 2);
+	  /* Remember IDENTS seen so far.  Among these will be the member
+	     name.  */
+	  id = (char *) xrealloc (id, strlen (yytext) + 2);
 	  if (tilde)
 	    {
 	      *id = '~';
@@ -2586,7 +2598,11 @@
 	  break;
 
         case OPERATOR:
-          id = operator_name (&sc);
+	  {
+	    char *s = operator_name (&sc);
+	    id = (char *) xrealloc (id, strlen (s) + 1);
+	    strcpy (id, s);
+	  }
           break;
 
         case '(':
@@ -2616,7 +2632,8 @@
 
           if (LOOKING_AT ('{') && id && cls)
 	    add_member_defn (cls, id, regexp, pos, hash, 0, sc, flags);
-	  
+
+	  xfree (id);
           id = NULL;
           sc = SC_MEMBER;
           break;
@@ -2694,6 +2711,8 @@
       skip_matching ();
       print_info ();
     }
+
+  xfree (id);
 }
 
 
@@ -3111,7 +3130,10 @@
           /* This is for the case `STARTWRAP class X : ...' or
              `declare (X, Y)\n class A : ...'.  */
           if (id)
-            return;
+	    {
+	      xfree (id);
+	      return;
+	    }
 
         case '=':
           /* Assumed to be the start of an initialization in this context.
@@ -3120,7 +3142,11 @@
           break;
 
         case OPERATOR:
-          id = operator_name (&sc);
+	  {
+	    char *s = operator_name (&sc);
+	    id = (char *) xrealloc (id, strlen (s) + 1);
+	    strcpy (id, s);
+	  }
           break;
 
         case T_INLINE:
@@ -3132,7 +3158,7 @@
 	  MATCH ();
 	  if (LOOKING_AT (IDENT))
 	    {
-	      id = (char *) alloca (strlen (yytext) + 2);
+	      id = (char *) xrealloc (id, strlen (yytext) + 2);
 	      *id = '~';
 	      strcpy (id + 1, yytext);
 	      MATCH ();
@@ -3194,6 +3220,8 @@
 
           if (!cls && id && LOOKING_AT ('{'))
 	    add_global_defn (id, regexp, pos, hash, 0, sc, flags);
+
+	  xfree (id);
           id = NULL;
           break;
         }
@@ -3231,6 +3259,8 @@
       skip_matching ();
       print_info ();
     }
+
+  xfree (id);
 }
 
 
@@ -3259,9 +3289,7 @@
 
             if (LOOKING_AT (IDENT))
               {
-                char *namespace_name
-		  = (char *) alloca (strlen (yytext) + 1);
-                strcpy (namespace_name, yytext);
+                char *namespace_name = xstrdup (yytext);
                 MATCH ();
                 
                 if (LOOKING_AT ('='))
@@ -3278,6 +3306,8 @@
                     leave_namespace ();
                     MATCH_IF ('}');
                   }
+
+		xfree (namespace_name);
               }
           }
           break;