[asterisk-commits] murf: branch group/mime r61633 - /team/group/mime/main/minimime/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Apr 12 12:43:49 MST 2007


Author: murf
Date: Thu Apr 12 14:43:48 2007
New Revision: 61633

URL: http://svn.digium.com/view/asterisk?view=rev&rev=61633
Log:
(almost) valgrind clean-- the global lib vars need to be pulled into local structures to make things threadsafe

Modified:
    team/group/mime/main/minimime/lexfix
    team/group/mime/main/minimime/mimeparser.l
    team/group/mime/main/minimime/mimeparser.tab.c
    team/group/mime/main/minimime/mimeparser.y
    team/group/mime/main/minimime/mimeparser.yy.c
    team/group/mime/main/minimime/mm_contenttype.c
    team/group/mime/main/minimime/mm_context.c
    team/group/mime/main/minimime/mm_queue.h

Modified: team/group/mime/main/minimime/lexfix
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/lexfix?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/lexfix (original)
+++ team/group/mime/main/minimime/lexfix Thu Apr 12 14:43:48 2007
@@ -1,5 +1,5 @@
---- mimeparser.yy.c	2007-04-11 17:43:49.000000000 -0600
-+++ mimeparser.yy.c.fixed	2007-04-11 17:43:14.000000000 -0600
+--- mimeparser.yy.c	2007-04-12 13:10:12.000000000 -0600
++++ mimeparser.yy.c.fixed	2007-04-12 13:08:49.000000000 -0600
 @@ -1769,7 +1769,7 @@
  			yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_buf_size;
  
@@ -54,3 +54,14 @@
  
  	/* It's okay to grow etc. this buffer, and we should throw it
  	 * away when we're done.
+@@ -2484,8 +2484,10 @@
+ 	yyg->yy_buffer_stack = NULL;
+ 
+     /* Destroy the start condition stack. */
++	if (yyg->yy_start_stack) {
+         mimeparser_yyfree(yyg->yy_start_stack ,yyscanner );
+         yyg->yy_start_stack = NULL;
++	}
+ 
+     /* Destroy the main struct (reentrant only). */
+     mimeparser_yyfree ( yyscanner , yyscanner );

Modified: team/group/mime/main/minimime/mimeparser.l
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mimeparser.l?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mimeparser.l (original)
+++ team/group/mime/main/minimime/mimeparser.l Thu Apr 12 14:43:48 2007
@@ -98,7 +98,6 @@
 %%
 
 <INITIAL,headers>^[a-zA-Z]+[a-zA-Z0-9\-\_]* {
-	yylval_param->string=strdup(yytext); 
 	struct lexer_state *lstate = yyget_extra(yyscanner);
 	lstate->current_pos += yyleng;
 	BC(header);
@@ -119,6 +118,7 @@
 		lstate->header_state = STATE_MAIL;
 		return MIMEVERSION_HEADER;
 	} else {
+		yylval_param->string=strdup(yytext); 
 		lstate->header_state = STATE_MAIL;
 		return MAIL_HEADER;
 	}

Modified: team/group/mime/main/minimime/mimeparser.tab.c
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mimeparser.tab.c?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mimeparser.tab.c (original)
+++ team/group/mime/main/minimime/mimeparser.tab.c Thu Apr 12 14:43:48 2007
@@ -534,12 +534,12 @@
 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
 static const yytype_uint16 yyrline[] =
 {
-       0,   114,   114,   116,   121,   120,   133,   141,   143,   167,
-     171,   186,   190,   193,   197,   199,   203,   218,   220,   230,
-     232,   234,   236,   250,   257,   276,   284,   294,   300,   308,
-     331,   338,   345,   349,   351,   355,   364,   366,   368,   382,
-     384,   386,   400,   431,   445,   451,   466,   474,   481,   500,
-     519
+       0,   114,   114,   126,   139,   138,   151,   160,   162,   186,
+     190,   205,   209,   212,   216,   218,   222,   237,   239,   249,
+     251,   253,   255,   269,   278,   298,   307,   318,   326,   336,
+     359,   368,   376,   380,   382,   386,   400,   402,   404,   418,
+     420,   422,   436,   467,   481,   487,   502,   510,   517,   539,
+     559
 };
 #endif
 
@@ -1512,8 +1512,34 @@
   YY_REDUCE_PRINT (yyn);
   switch (yyn)
     {
-        case 4:
-#line 121 "mimeparser.y"
+        case 2:
+#line 115 "mimeparser.y"
+    {
+		if (pstate->ctype)
+			mm_content_free(pstate->ctype);
+		if (pstate->current_mimepart)
+			free(pstate->current_mimepart);
+		if (pstate->lstate.boundary_string)
+			free(pstate->lstate.boundary_string);
+		if (pstate->lstate.endboundary_string)
+			free(pstate->lstate.endboundary_string);
+	;}
+    break;
+
+  case 3:
+#line 127 "mimeparser.y"
+    {
+		if (pstate->ctype)
+			mm_content_free(pstate->ctype);
+		if (pstate->lstate.boundary_string)
+			free(pstate->lstate.boundary_string);
+		if (pstate->lstate.endboundary_string)
+			free(pstate->lstate.endboundary_string);
+	;}
+    break;
+
+  case 4:
+#line 139 "mimeparser.y"
     { 
 		mm_context_attachpart(pstate->ctx, pstate->current_mimepart);
 		pstate->current_mimepart = mm_mimepart_new();
@@ -1522,22 +1548,23 @@
     break;
 
   case 5:
-#line 127 "mimeparser.y"
+#line 145 "mimeparser.y"
     {
 		dprintf2(pstate,"This was a multipart message\n");
 	;}
     break;
 
   case 6:
-#line 134 "mimeparser.y"
+#line 152 "mimeparser.y"
     {
 		dprintf2(pstate,"This was a single part message\n");
 		mm_context_attachpart(pstate->ctx, pstate->current_mimepart);
+		pstate->current_mimepart = 0;
 	;}
     break;
 
   case 8:
-#line 144 "mimeparser.y"
+#line 163 "mimeparser.y"
     {
 		/* If we did not find a Content-Type header for the current
 		 * MIME part (or envelope), we create one and attach it.
@@ -1563,7 +1590,7 @@
     break;
 
   case 10:
-#line 172 "mimeparser.y"
+#line 191 "mimeparser.y"
     {
 		char *preamble;
 		size_t offset;
@@ -1581,13 +1608,13 @@
     break;
 
   case 12:
-#line 191 "mimeparser.y"
+#line 210 "mimeparser.y"
     {
 	;}
     break;
 
   case 16:
-#line 204 "mimeparser.y"
+#line 223 "mimeparser.y"
     {
 
 		if (mm_context_attachpart(pstate->ctx, pstate->current_mimepart) == -1) {
@@ -1602,7 +1629,7 @@
     break;
 
   case 18:
-#line 221 "mimeparser.y"
+#line 240 "mimeparser.y"
     {
 		pstate->have_contenttype = 1;
 		if (mm_content_iscomposite(pstate->envelope->type)) {
@@ -1614,7 +1641,7 @@
     break;
 
   case 22:
-#line 237 "mimeparser.y"
+#line 256 "mimeparser.y"
     {
 		if (pstate->parsemode != MM_PARSE_LOOSE) {
 			mm_errno = MM_ERROR_PARSE;
@@ -1628,16 +1655,18 @@
     break;
 
   case 23:
-#line 251 "mimeparser.y"
+#line 270 "mimeparser.y"
     {
 		struct mm_mimeheader *hdr;
 		hdr = mm_mimeheader_generate((yyvsp[(1) - (4)].string), (yyvsp[(3) - (4)].string));
+		free((yyvsp[(1) - (4)].string)); /* mimeheader_generate strdups each arg, so you need to free the WORDS */
+		free((yyvsp[(3) - (4)].string));
 		mm_mimepart_attachheader(pstate->current_mimepart, hdr);
 	;}
     break;
 
   case 24:
-#line 258 "mimeparser.y"
+#line 279 "mimeparser.y"
     {
 		struct mm_mimeheader *hdr;
 
@@ -1650,49 +1679,56 @@
 			/* TODO: attach MM_WARNING_INVHDR */
 		}	
 		
-		hdr = mm_mimeheader_generate((yyvsp[(1) - (3)].string), xstrdup(""));
+		hdr = mm_mimeheader_generate((yyvsp[(1) - (3)].string), "");
+		free((yyvsp[(1) - (3)].string)); /* mimeheader_generate strdups each arg, so you need to free the WORDS */
 		mm_mimepart_attachheader(pstate->current_mimepart, hdr);
 	;}
     break;
 
   case 25:
-#line 277 "mimeparser.y"
+#line 299 "mimeparser.y"
     {
 		mm_content_settype(pstate->ctype, "%s", (yyvsp[(3) - (4)].string));
 		mm_mimepart_attachcontenttype(pstate->current_mimepart, pstate->ctype);
 		dprintf2(pstate,"Content-Type -> %s\n", (yyvsp[(3) - (4)].string));
+		free((yyvsp[(3) - (4)].string));
 		pstate->ctype = mm_content_new();
 	;}
     break;
 
   case 26:
-#line 285 "mimeparser.y"
+#line 308 "mimeparser.y"
     {
 		mm_content_settype(pstate->ctype, "%s", (yyvsp[(3) - (5)].string));
 		mm_mimepart_attachcontenttype(pstate->current_mimepart, pstate->ctype);
 		dprintf2(pstate,"Content-Type (P) -> %s\n", (yyvsp[(3) - (5)].string));
+		free((yyvsp[(3) - (5)].string));
 		pstate->ctype = mm_content_new();
 	;}
     break;
 
   case 27:
-#line 295 "mimeparser.y"
+#line 319 "mimeparser.y"
     {
 		dprintf2(pstate,"Content-Disposition -> %s\n", (yyvsp[(3) - (4)].string));
-		pstate->ctype->disposition_type = xstrdup((yyvsp[(3) - (4)].string));
+		if (pstate->ctype->disposition_type)
+			free(pstate->ctype->disposition_type);
+		pstate->ctype->disposition_type = (yyvsp[(3) - (4)].string); /* content_disposition is a WORD, which is already copied */
 	;}
     break;
 
   case 28:
-#line 301 "mimeparser.y"
+#line 327 "mimeparser.y"
     {
 		dprintf2(pstate,"Content-Disposition (P) -> %s; params\n", (yyvsp[(3) - (5)].string));
-		pstate->ctype->disposition_type = xstrdup((yyvsp[(3) - (5)].string));
+		if (pstate->ctype->disposition_type)
+			free(pstate->ctype->disposition_type);
+		pstate->ctype->disposition_type = (yyvsp[(3) - (5)].string); /* content_disposition is a WORD, which is already copied */
 	;}
     break;
 
   case 29:
-#line 309 "mimeparser.y"
+#line 337 "mimeparser.y"
     {
 		/*
 		 * According to RFC 2183, the content disposition value may
@@ -1715,30 +1751,38 @@
     break;
 
   case 30:
-#line 332 "mimeparser.y"
+#line 360 "mimeparser.y"
     {
 		dprintf2(pstate,"Content-Transfer-Encoding -> %s\n", (yyvsp[(3) - (4)].string));
+		free((yyvsp[(3) - (4)].string)); /* until we use this */
+		
 	;}
     break;
 
   case 31:
-#line 339 "mimeparser.y"
+#line 369 "mimeparser.y"
     {
 		dprintf2(pstate,"MIME-Version -> '%s'\n", (yyvsp[(3) - (4)].string));
+		free((yyvsp[(3) - (4)].string)); /* until we use this */
 	;}
     break;
 
   case 35:
-#line 356 "mimeparser.y"
-    {
-		char type[255];
-		snprintf(type, sizeof(type), "%s/%s", (yyvsp[(1) - (3)].string), (yyvsp[(3) - (3)].string));
-		(yyval.string) = type;
+#line 387 "mimeparser.y"
+    {
+		char *combo;
+		combo = xmalloc(strlen((yyvsp[(1) - (3)].string))+strlen((yyvsp[(3) - (3)].string))+2);
+		strcpy(combo,(yyvsp[(1) - (3)].string));
+		strcat(combo,"/");
+		strcat(combo,(yyvsp[(3) - (3)].string));
+		free((yyvsp[(1) - (3)].string));
+		free((yyvsp[(3) - (3)].string));
+		(yyval.string)=combo;
 	;}
     break;
 
   case 38:
-#line 369 "mimeparser.y"
+#line 405 "mimeparser.y"
     {
 		if (pstate->parsemode != MM_PARSE_LOOSE) {
 			mm_errno = MM_ERROR_MIME;
@@ -1752,7 +1796,7 @@
     break;
 
   case 41:
-#line 387 "mimeparser.y"
+#line 423 "mimeparser.y"
     {	
 		if (pstate->parsemode != MM_PARSE_LOOSE) {
 			mm_errno = MM_ERROR_MIME;
@@ -1766,7 +1810,7 @@
     break;
 
   case 42:
-#line 401 "mimeparser.y"
+#line 437 "mimeparser.y"
     {
 		struct mm_param *param;
 		param = mm_param_new();
@@ -1789,21 +1833,21 @@
 			}
 		}
 
-		param->name = xstrdup((yyvsp[(1) - (3)].string));
-		param->value = xstrdup((yyvsp[(3) - (3)].string));
+		param->name = (yyvsp[(1) - (3)].string); /* WORD is alloc'd, no need to dup it */
+		param->value = (yyvsp[(3) - (3)].string); /* WORD is alloc'd, no need to dup it */
 
 		mm_content_attachtypeparam(pstate->ctype, param);
 	;}
     break;
 
   case 43:
-#line 432 "mimeparser.y"
+#line 468 "mimeparser.y"
     {
 		struct mm_param *param;
 		param = mm_param_new();
 		
-		param->name = xstrdup((yyvsp[(1) - (3)].string));
-		param->value = xstrdup((yyvsp[(3) - (3)].string));
+		param->name = (yyvsp[(1) - (3)].string); /* both these vals already allocated, no need to leak them */
+		param->value = (yyvsp[(3) - (3)].string);
 
 		mm_content_attachdispositionparam(pstate->ctype, param);
 
@@ -1811,7 +1855,7 @@
     break;
 
   case 44:
-#line 446 "mimeparser.y"
+#line 482 "mimeparser.y"
     {
 		dprintf2(pstate,"contenttype_param_val: WORD=%s\n", (yyvsp[(1) - (1)].string));
 		(yyval.string) = (yyvsp[(1) - (1)].string);
@@ -1819,7 +1863,7 @@
     break;
 
   case 45:
-#line 452 "mimeparser.y"
+#line 488 "mimeparser.y"
     {
 		dprintf2(pstate,"contenttype_param_val: TSPECIAL\n");
 		/* For broken MIME implementation */
@@ -1836,7 +1880,7 @@
     break;
 
   case 46:
-#line 467 "mimeparser.y"
+#line 503 "mimeparser.y"
     {
 		dprintf2(pstate,"contenttype_param_val: \"TSPECIAL\"\n" );
 		(yyval.string) = (yyvsp[(2) - (3)].string);
@@ -1844,14 +1888,14 @@
     break;
 
   case 47:
-#line 475 "mimeparser.y"
+#line 511 "mimeparser.y"
     {
 		dprintf2(pstate,"End of headers at line %d\n", pstate->lstate.lineno);
 	;}
     break;
 
   case 48:
-#line 482 "mimeparser.y"
+#line 518 "mimeparser.y"
     {
 		if (pstate->lstate.boundary_string == NULL) {
 			mm_errno = MM_ERROR_PARSE;
@@ -1866,11 +1910,14 @@
 			return(-1);
 		}
 		dprintf2(pstate,"New MIME part... (%s)\n", (yyvsp[(1) - (2)].string));
+		/* if the BOUNDARY token value isn't used anywhere, then free it! */
+		if ((yyvsp[(1) - (2)].string))
+			free((yyvsp[(1) - (2)].string));
 	;}
     break;
 
   case 49:
-#line 501 "mimeparser.y"
+#line 540 "mimeparser.y"
     {
 		if (pstate->lstate.endboundary_string == NULL) {
 			mm_errno = MM_ERROR_PARSE;
@@ -1885,11 +1932,12 @@
 			return(-1);
 		}
 		dprintf2(pstate,"End of MIME message\n");
+		free((yyvsp[(1) - (1)].string)); /* if we don't use this anything, might as well free it */
 	;}
     break;
 
   case 50:
-#line 520 "mimeparser.y"
+#line 560 "mimeparser.y"
     {
 		char *body;
 		size_t offset;
@@ -1911,7 +1959,7 @@
 
 
 /* Line 1267 of yacc.c.  */
-#line 1915 "mimeparser.tab.c"
+#line 1963 "mimeparser.tab.c"
       default: break;
     }
   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
@@ -2125,7 +2173,7 @@
 }
 
 
-#line 539 "mimeparser.y"
+#line 579 "mimeparser.y"
 
 
 /*
@@ -2246,7 +2294,11 @@
 
 	blen = strlen(str);
 
+	if (pstate->lstate.boundary_string)
+		free(pstate->lstate.boundary_string);
 	pstate->lstate.boundary_string = (char *)malloc(blen + 3);
+	if (pstate->lstate.endboundary_string)
+		free(pstate->lstate.endboundary_string);
 	pstate->lstate.endboundary_string = (char *)malloc(blen + 5);
 
 	if (pstate->lstate.boundary_string == NULL || pstate->lstate.endboundary_string == NULL) {

Modified: team/group/mime/main/minimime/mimeparser.y
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mimeparser.y?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mimeparser.y (original)
+++ team/group/mime/main/minimime/mimeparser.y Thu Apr 12 14:43:48 2007
@@ -112,8 +112,26 @@
  */
 message : 
 	multipart_message
-	|
-	singlepart_message
+	{
+		if (pstate->ctype)
+			mm_content_free(pstate->ctype);
+		if (pstate->current_mimepart)
+			free(pstate->current_mimepart);
+		if (pstate->lstate.boundary_string)
+			free(pstate->lstate.boundary_string);
+		if (pstate->lstate.endboundary_string)
+			free(pstate->lstate.endboundary_string);
+	}
+	|
+	singlepart_message 
+	{
+		if (pstate->ctype)
+			mm_content_free(pstate->ctype);
+		if (pstate->lstate.boundary_string)
+			free(pstate->lstate.boundary_string);
+		if (pstate->lstate.endboundary_string)
+			free(pstate->lstate.endboundary_string);
+	}
 	;
 
 multipart_message:
@@ -134,6 +152,7 @@
 	{
 		dprintf2(pstate,"This was a single part message\n");
 		mm_context_attachpart(pstate->ctx, pstate->current_mimepart);
+		pstate->current_mimepart = 0;
 	}
 	;
 	
@@ -251,6 +270,8 @@
 	{
 		struct mm_mimeheader *hdr;
 		hdr = mm_mimeheader_generate($1, $3);
+		free($1); /* mimeheader_generate strdups each arg, so you need to free the WORDS */
+		free($3);
 		mm_mimepart_attachheader(pstate->current_mimepart, hdr);
 	}
 	|
@@ -267,7 +288,8 @@
 			/* TODO: attach MM_WARNING_INVHDR */
 		}	
 		
-		hdr = mm_mimeheader_generate($1, xstrdup(""));
+		hdr = mm_mimeheader_generate($1, "");
+		free($1); /* mimeheader_generate strdups each arg, so you need to free the WORDS */
 		mm_mimepart_attachheader(pstate->current_mimepart, hdr);
 	}
 	;
@@ -278,6 +300,7 @@
 		mm_content_settype(pstate->ctype, "%s", $3);
 		mm_mimepart_attachcontenttype(pstate->current_mimepart, pstate->ctype);
 		dprintf2(pstate,"Content-Type -> %s\n", $3);
+		free($3);
 		pstate->ctype = mm_content_new();
 	}
 	|
@@ -286,6 +309,7 @@
 		mm_content_settype(pstate->ctype, "%s", $3);
 		mm_mimepart_attachcontenttype(pstate->current_mimepart, pstate->ctype);
 		dprintf2(pstate,"Content-Type (P) -> %s\n", $3);
+		free($3);
 		pstate->ctype = mm_content_new();
 	}
 	;
@@ -294,13 +318,17 @@
 	CONTENTDISPOSITION_HEADER COLON content_disposition EOL
 	{
 		dprintf2(pstate,"Content-Disposition -> %s\n", $3);
-		pstate->ctype->disposition_type = xstrdup($3);
+		if (pstate->ctype->disposition_type)
+			free(pstate->ctype->disposition_type);
+		pstate->ctype->disposition_type = $3; /* content_disposition is a WORD, which is already copied */
 	}
 	|
 	CONTENTDISPOSITION_HEADER COLON content_disposition content_disposition_parameters EOL
 	{
 		dprintf2(pstate,"Content-Disposition (P) -> %s; params\n", $3);
-		pstate->ctype->disposition_type = xstrdup($3);
+		if (pstate->ctype->disposition_type)
+			free(pstate->ctype->disposition_type);
+		pstate->ctype->disposition_type = $3; /* content_disposition is a WORD, which is already copied */
 	}
 	;
 
@@ -331,6 +359,8 @@
 	CONTENTENCODING_HEADER COLON WORD EOL
 	{
 		dprintf2(pstate,"Content-Transfer-Encoding -> %s\n", $3);
+		free($3); /* until we use this */
+		
 	}
 	;
 
@@ -338,6 +368,7 @@
 	MIMEVERSION_HEADER COLON WORD EOL
 	{
 		dprintf2(pstate,"MIME-Version -> '%s'\n", $3);
+		free($3); /* until we use this */
 	}
 	;
 
@@ -354,9 +385,14 @@
 mimetype:
 	WORD '/' WORD
 	{
-		char type[255];
-		snprintf(type, sizeof(type), "%s/%s", $1, $3);
-		$$ = type;
+		char *combo;
+		combo = xmalloc(strlen($1)+strlen($3)+2);
+		strcpy(combo,$1);
+		strcat(combo,"/");
+		strcat(combo,$3);
+		free($1);
+		free($3);
+		$$=combo;
 	}	
 	;
 
@@ -420,8 +456,8 @@
 			}
 		}
 
-		param->name = xstrdup($1);
-		param->value = xstrdup($3);
+		param->name = $1; /* WORD is alloc'd, no need to dup it */
+		param->value = $3; /* WORD is alloc'd, no need to dup it */
 
 		mm_content_attachtypeparam(pstate->ctype, param);
 	}
@@ -433,8 +469,8 @@
 		struct mm_param *param;
 		param = mm_param_new();
 		
-		param->name = xstrdup($1);
-		param->value = xstrdup($3);
+		param->name = $1; /* both these vals already allocated, no need to leak them */
+		param->value = $3;
 
 		mm_content_attachdispositionparam(pstate->ctype, param);
 
@@ -493,6 +529,9 @@
 			return(-1);
 		}
 		dprintf2(pstate,"New MIME part... (%s)\n", $1);
+		/* if the BOUNDARY token value isn't used anywhere, then free it! */
+		if ($1)
+			free($1);
 	}
 	;
 
@@ -512,6 +551,7 @@
 			return(-1);
 		}
 		dprintf2(pstate,"End of MIME message\n");
+		free($1); /* if we don't use this anything, might as well free it */
 	}
 	;
 
@@ -656,7 +696,11 @@
 
 	blen = strlen(str);
 
+	if (pstate->lstate.boundary_string)
+		free(pstate->lstate.boundary_string);
 	pstate->lstate.boundary_string = (char *)malloc(blen + 3);
+	if (pstate->lstate.endboundary_string)
+		free(pstate->lstate.endboundary_string);
 	pstate->lstate.endboundary_string = (char *)malloc(blen + 5);
 
 	if (pstate->lstate.boundary_string == NULL || pstate->lstate.endboundary_string == NULL) {

Modified: team/group/mime/main/minimime/mimeparser.yy.c
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mimeparser.yy.c?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mimeparser.yy.c (original)
+++ team/group/mime/main/minimime/mimeparser.yy.c Thu Apr 12 14:43:48 2007
@@ -974,7 +974,6 @@
 YY_RULE_SETUP
 #line 100 "mimeparser.l"
 {
-	yylval_param->string=strdup(yytext); 
 	struct lexer_state *lstate = mimeparser_yyget_extra(yyscanner);
 	lstate->current_pos += yyleng;
 	BC(header);
@@ -995,6 +994,7 @@
 		lstate->header_state = STATE_MAIL;
 		return MIMEVERSION_HEADER;
 	} else {
+		yylval_param->string=strdup(yytext); 
 		lstate->header_state = STATE_MAIL;
 		return MAIL_HEADER;
 	}
@@ -2484,8 +2484,10 @@
 	yyg->yy_buffer_stack = NULL;
 
     /* Destroy the start condition stack. */
+	if (yyg->yy_start_stack) {
         mimeparser_yyfree(yyg->yy_start_stack ,yyscanner );
         yyg->yy_start_stack = NULL;
+	}
 
     /* Destroy the main struct (reentrant only). */
     mimeparser_yyfree ( yyscanner , yyscanner );

Modified: team/group/mime/main/minimime/mm_contenttype.c
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mm_contenttype.c?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mm_contenttype.c (original)
+++ team/group/mime/main/minimime/mm_contenttype.c Thu Apr 12 14:43:48 2007
@@ -96,6 +96,7 @@
 
 	ct->maintype = NULL;
 	ct->subtype = NULL;
+	ct->disposition_type = NULL;
 
 	TAILQ_INIT(&ct->type_params);
 	TAILQ_INIT(&ct->disposition_params);
@@ -116,7 +117,7 @@
 void
 mm_content_free(struct mm_content *ct)
 {
-	struct mm_param *param;
+	struct mm_param *param, *param2;
 
 	assert(ct != NULL);
 
@@ -132,12 +133,18 @@
 		xfree(ct->encstring);
 		ct->encstring = NULL;
 	}
-
-	TAILQ_FOREACH(param, &ct->type_params, next) {
+	if (ct->disposition_type != NULL) {
+		xfree(ct->disposition_type);
+		ct->disposition_type = NULL;
+	}
+
+	TAILQ_FOREACH_SAFE(param, param2, &ct->type_params, next) {
+		param2 = TAILQ_NEXT(param,next);
 		TAILQ_REMOVE(&ct->type_params, param, next);
 		mm_param_free(param);
 	}	
-	TAILQ_FOREACH(param, &ct->disposition_params, next) {
+	TAILQ_FOREACH_SAFE(param, param2, &ct->disposition_params, next) {
+		param2 = TAILQ_NEXT(param,next);
 		TAILQ_REMOVE(&ct->disposition_params, param, next);
 		mm_param_free(param);
 	}	

Modified: team/group/mime/main/minimime/mm_context.c
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mm_context.c?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mm_context.c (original)
+++ team/group/mime/main/minimime/mm_context.c Thu Apr 12 14:43:48 2007
@@ -102,12 +102,13 @@
 void
 mm_context_free(MM_CTX *ctx)
 {
-	struct mm_mimepart *part;
+	struct mm_mimepart *part, *part2;
 	struct mm_warning *warning, *nxt;
 	
 	assert(ctx != NULL);
 
-	TAILQ_FOREACH(part, &ctx->parts, next) {
+	TAILQ_FOREACH_SAFE(part, part2, &ctx->parts, next) {
+		part2 = TAILQ_NEXT(part,next);
 		TAILQ_REMOVE(&ctx->parts, part, next);
 		mm_mimepart_free(part);
 	}

Modified: team/group/mime/main/minimime/mm_queue.h
URL: http://svn.digium.com/view/asterisk/team/group/mime/main/minimime/mm_queue.h?view=diff&rev=61633&r1=61632&r2=61633
==============================================================================
--- team/group/mime/main/minimime/mm_queue.h (original)
+++ team/group/mime/main/minimime/mm_queue.h Thu Apr 12 14:43:48 2007
@@ -326,6 +326,11 @@
 	    (var) != TAILQ_END(head);					\
 	    (var) = TAILQ_NEXT(var, field))
 
+#define TAILQ_FOREACH_SAFE(var, var2, head, field)	\
+	for((var) = TAILQ_FIRST(head);					\
+	    (var) != TAILQ_END(head);					\
+	    (var) = (var2))
+
 #define TAILQ_FOREACH_REVERSE(var, head, headname, field)		\
 	for((var) = TAILQ_LAST(head, headname);				\
 	    (var) != TAILQ_END(head);					\



More information about the asterisk-commits mailing list