[asterisk-commits] trunk - r7737 in /trunk: ./ ast_expr2.fl ast_expr2f.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Jan 3 10:39:38 CST 2006


Author: kpfleming
Date: Tue Jan  3 10:39:37 2006
New Revision: 7737

URL: http://svn.digium.com/view/asterisk?rev=7737&view=rev
Log:
Merged revisions 7736 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r7736 | kpfleming | 2006-01-03 10:34:12 -0600 (Tue, 03 Jan 2006) | 2 lines

don't leak memory for (most) expression evaluations

........

Modified:
    trunk/   (props changed)
    trunk/ast_expr2.fl
    trunk/ast_expr2f.c

Propchange: trunk/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Jan  3 10:39:37 2006
@@ -1,1 +1,1 @@
-/branches/1.2:1-7489,7491-7496,7498-7516,7518-7528,7530-7545,7547-7549,7551,7553-7556,7558-7579,7581-7585,7587-7594,7596-7604,7606-7640,7642-7662,7664-7665,7677,7709
+/branches/1.2:1-7489,7491-7496,7498-7516,7518-7528,7530-7545,7547-7549,7551,7553-7556,7558-7579,7581-7585,7587-7594,7596-7604,7606-7640,7642-7662,7664-7705,7707-7736

Modified: trunk/ast_expr2.fl
URL: http://svn.digium.com/view/asterisk/trunk/ast_expr2.fl?rev=7737&r1=7736&r2=7737&view=diff
==============================================================================
--- trunk/ast_expr2.fl (original)
+++ trunk/ast_expr2.fl Tue Jan  3 10:39:37 2006
@@ -98,42 +98,42 @@
 
 int ast_expr(char *expr, char *buf, int length)
 {
-	struct parse_io *io;
+	struct parse_io io;
+	int return_value = 0;
 	
-	io = calloc(sizeof(struct parse_io),1);
-	io->string = expr;  /* to pass to the error routine */
+	memset(&io, 0, sizeof(io));
+	io.string = expr;  /* to pass to the error routine */
 	
-	ast_yylex_init(&io->scanner);
+	ast_yylex_init(&io.scanner);
 	
-	ast_yy_scan_string(expr, io->scanner);
+	ast_yy_scan_string(expr, io.scanner);
 	
-	ast_yyparse ((void *) io);
+	ast_yyparse ((void *) &io);
 
-	ast_yylex_destroy(io->scanner);
+	ast_yylex_destroy(io.scanner);
 
-	if (io->val == NULL) {
+	if (!io.val) {
 		if (length > 1) {
 			strcpy(buf, "0");
-			return 1;
+			return_value = 1;
 		}
 	} else {
-		if (io->val->type == AST_EXPR_integer) {
+		if (io.val->type == AST_EXPR_integer) {
 			int res_length;
 
-			res_length = snprintf(buf, length, "%ld", (long int) io->val->u.i);
-			return res_length <= length ? res_length : length;
+			res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
+			return_value = (res_length <= length) ? res_length : length;
 		} else {
 #ifdef STANDALONE
-			strncpy(buf, io->val->u.s, length - 1);
+			strncpy(buf, io.val->u.s, length - 1);
 #else /* !STANDALONE */
-			ast_copy_string(buf, io->val->u.s, length);
+			ast_copy_string(buf, io.val->u.s, length);
 #endif /* STANDALONE */
-			return strlen(buf);
+			return_value = strlen(buf);
 		}
-		free(io->val);
+		free(io.val);
 	}
-	free(io);
-	return 0;
+	return return_value;
 }
 
 int ast_yyerror (const char *s,  yyltype *loc, struct parse_io *parseio )

Modified: trunk/ast_expr2f.c
URL: http://svn.digium.com/view/asterisk/trunk/ast_expr2f.c?rev=7737&r1=7736&r2=7737&view=diff
==============================================================================
--- trunk/ast_expr2f.c (original)
+++ trunk/ast_expr2f.c Tue Jan  3 10:39:37 2006
@@ -2562,42 +2562,42 @@
 
 int ast_expr(char *expr, char *buf, int length)
 {
-	struct parse_io *io;
+	struct parse_io io;
+	int return_value = 0;
 	
-	io = calloc(sizeof(struct parse_io),1);
-	io->string = expr;  /* to pass to the error routine */
+	memset(&io, 0, sizeof(io));
+	io.string = expr;  /* to pass to the error routine */
 	
-	ast_yylex_init(&io->scanner);
+	ast_yylex_init(&io.scanner);
 	
-	ast_yy_scan_string(expr, io->scanner);
+	ast_yy_scan_string(expr, io.scanner);
 	
-	ast_yyparse ((void *) io);
-
-	ast_yylex_destroy(io->scanner);
-
-	if (io->val == NULL) {
+	ast_yyparse ((void *) &io);
+
+	ast_yylex_destroy(io.scanner);
+
+	if (!io.val) {
 		if (length > 1) {
 			strcpy(buf, "0");
-			return 1;
+			return_value = 1;
 		}
 	} else {
-		if (io->val->type == AST_EXPR_integer) {
+		if (io.val->type == AST_EXPR_integer) {
 			int res_length;
 
-			res_length = snprintf(buf, length, "%ld", (long int) io->val->u.i);
-			return res_length <= length ? res_length : length;
+			res_length = snprintf(buf, length, "%ld", (long int) io.val->u.i);
+			return_value = (res_length <= length) ? res_length : length;
 		} else {
 #ifdef STANDALONE
-			strncpy(buf, io->val->u.s, length - 1);
+			strncpy(buf, io.val->u.s, length - 1);
 #else /* !STANDALONE */
-			ast_copy_string(buf, io->val->u.s, length);
+			ast_copy_string(buf, io.val->u.s, length);
 #endif /* STANDALONE */
-			return strlen(buf);
+			return_value = strlen(buf);
 		}
-		free(io->val);
+		free(io.val);
 	}
-	free(io);
-	return 0;
+	return return_value;
 }
 
 int ast_yyerror (const char *s,  yyltype *loc, struct parse_io *parseio )



More information about the asterisk-commits mailing list