[Asterisk-cvs] asterisk chanvars.c,1.5,1.6

markster at lists.digium.com markster at lists.digium.com
Mon Nov 1 10:46:06 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv21597

Modified Files:
	chanvars.c 
Log Message:
Little variable optimizations


Index: chanvars.c
===================================================================
RCS file: /usr/cvsroot/asterisk/chanvars.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- chanvars.c	1 Nov 2004 02:23:27 -0000	1.5
+++ chanvars.c	1 Nov 2004 15:48:42 -0000	1.6
@@ -21,8 +21,14 @@
 {
 	int i;
 	struct ast_var_t *var;
+	int len;
 	
-	var = malloc(sizeof(struct ast_var_t));
+	len = sizeof(struct ast_var_t);
+	
+	len += strlen(name) + 1;
+	len += strlen(value) + 1;
+	
+	var = malloc(len);
 
 	if (var == NULL)
 	{
@@ -30,41 +36,22 @@
 		return NULL;
 	}
 	
-	i = strlen(value);
-	var->value = malloc(i + 1);
-	if (var->value == NULL)
-	{
-		ast_log(LOG_WARNING, "Out of memory\n");
-		free(var);
-		return NULL;
-	}
-
-	strncpy(var->value, value, i);
-	var->value[i] = '\0';
-	
 	i = strlen(name);
-	var->name = malloc(i + 1);
-	if (var->name == NULL)
-	{
-		ast_log(LOG_WARNING, "Out of memory\n");
-		free(var->value);
-		free(var);
-		return NULL;
-	}
-
 	strncpy(var->name, name, i); 
 	var->name[i] = '\0';
 
+	var->value = var->name + i + 1;
+
+	i = strlen(value);
+	strncpy(var->value, value, i);
+	var->value[i] = '\0';
+	
 	return var;
 }	
 	
 void ast_var_delete(struct ast_var_t *var)
 {
 	if (var == NULL) return;
-
-	if (var->name != NULL) free(var->name);
-	if (var->value != NULL) free(var->value);
-
 	free(var);
 }
 




More information about the svn-commits mailing list