[svn-commits] anthonyl: branch anthonyl/8678-commentbuffer r49041 - /team/anthonyl/8678-com...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Dec 28 16:46:04 MST 2006


Author: anthonyl
Date: Thu Dec 28 17:46:03 2006
New Revision: 49041

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49041
Log:
this contains debugging information as well as a piliminary fix for the lline_buffer recursion issue which has been causing segfaults when processing a text based configuration file using the comment buffer

Modified:
    team/anthonyl/8678-commentbuffer/main/config.c

Modified: team/anthonyl/8678-commentbuffer/main/config.c
URL: http://svn.digium.com/view/asterisk/team/anthonyl/8678-commentbuffer/main/config.c?view=diff&rev=49041&r1=49040&r2=49041
==============================================================================
--- team/anthonyl/8678-commentbuffer/main/config.c (original)
+++ team/anthonyl/8678-commentbuffer/main/config.c Thu Dec 28 17:46:03 2006
@@ -86,6 +86,8 @@
 		comment_buffer[0] = 0;
 		comment_buffer_size = CB_INCR;
 		lline_buffer = ast_malloc(CB_INCR);
+		if (!lline_buffer)
+			return;
 		lline_buffer[0] = 0;
 		lline_buffer_size = CB_INCR;
 	} else {
@@ -127,8 +129,10 @@
 	int siz = strlen(str);
 	if (rem < siz+1) {
 		lline_buffer = ast_realloc(lline_buffer, lline_buffer_size + CB_INCR + siz + 1);
-		if (!lline_buffer)
+		if (!lline_buffer) {
+			ast_verbose("WARNING lline_buffer NULL\n");
 			return;
+		}
 		lline_buffer_size += CB_INCR + siz + 1;
 	}
 	strcat(lline_buffer,str);
@@ -167,6 +171,7 @@
 struct ast_category {
 	char name[80];
 	int ignored;			/*!< do not let user of the config see this category */
+	int include_level;	
 	struct ast_comment *precomments;
 	struct ast_comment *sameline;
 	struct ast_variable *root;
@@ -339,8 +344,10 @@
 		config->last->next = category;
 	else
 		config->root = category;
+	config->include_level = config->include_level;
 	config->last = category;
 	config->current = category;
+	ast_verbose("INCLUDE LEVEL: %i\n", config->include_level);
 }
 
 void ast_category_destroy(struct ast_category *cat)
@@ -796,6 +803,12 @@
 
 	if (withcomments) {
 		CB_INIT();
+		if (!lline_buffer || !comment_buffer) {
+			ast_log(LOG_ERROR, "Failed to initialize the comment buffer!\n");
+			return NULL;
+		}
+
+		ast_verbose("CB_INIT() called llinebuffer %p  comment_buffer %p\n", lline_buffer, comment_buffer);
 	}
 	
 #ifdef AST_INCLUDE_GLOB
@@ -848,6 +861,7 @@
 			lineno++;
 			if (fgets(buf, sizeof(buf), f)) {
 				if ( withcomments ) {    
+					ast_verbose("CB_ADD: lline_buffer (%p) for %s\n",lline_buffer, filename);
 					CB_ADD(lline_buffer);       /* add the current lline buffer to the comment buffer */
 					lline_buffer[0] = 0;        /* erase the lline buffer */
 				}
@@ -886,6 +900,7 @@
 								char *oldptr;
 								oldptr = process_buf + strlen(process_buf);
 								if ( withcomments ) {
+									ast_verbose("CB_ADD: (;)\n");
 									CB_ADD(";");
 									CB_ADD_LEN(oldptr+1,new_buf-oldptr-1);
 								}
@@ -910,6 +925,7 @@
 				}
 				if( withcomments && comment && !process_buf )
 				{
+					ast_verbose("CB_ADD buf(%p)\n", buf);
 					CB_ADD(buf);  /* the whole line is a comment, store it */
 				}
 				
@@ -937,16 +953,22 @@
 			}
 		}
 #endif
-	if (withcomments) {
-		if (comment_buffer) { 
-			free(comment_buffer);
-			free(lline_buffer);
-			comment_buffer=0; 
-			lline_buffer=0; 
-			comment_buffer_size=0; 
-			lline_buffer_size=0;
-		}
-	}
+
+	if (cfg->include_level == 1) {
+		if (withcomments) {
+			ast_verbose("LINE we are done processing %s\n", filename);
+			if (comment_buffer) { 
+				free(comment_buffer);
+				free(lline_buffer);
+				ast_verbose("free'ing llinebuffer\n");
+				comment_buffer=0; 
+				lline_buffer=0; 
+				comment_buffer_size=0; 
+				lline_buffer_size=0;
+			}
+		}
+	}
+	
 	if (count == 0)
 		return NULL;
 



More information about the svn-commits mailing list