From eb46be975ad61ab0fad940f3bbd568faba18fd8c Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Mon, 8 May 2006 19:56:43 +0000
Subject: [PATCH] Use alloca() instead of malloc()/free() where possible.

---
 src/xpdev/sockwrap.c | 9 +++------
 src/xpdev/str_list.c | 5 +----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/xpdev/sockwrap.c b/src/xpdev/sockwrap.c
index b0730b0477..864b02db91 100644
--- a/src/xpdev/sockwrap.c
+++ b/src/xpdev/sockwrap.c
@@ -35,7 +35,7 @@
  * Note: If this box doesn't appear square, then you need to fix your tabs.	*
  ****************************************************************************/
 
-#include <stdlib.h>		/* malloc/free on FreeBSD */
+#include <stdlib.h>		/* alloca/free on FreeBSD */
 #include <string.h>		/* bzero (for FD_ZERO) on FreeBSD */
 #include <errno.h>		/* ENOMEM */
 #include <stdio.h>		/* SEEK_SET */
@@ -245,7 +245,7 @@ int recvfilesocket(int sock, int file, long *offset, long count)
 		return(-1);
 	}
 		
-	if((buf=(char*)malloc(count))==NULL) {
+	if((buf=(char*)alloca(count))==NULL) {
 		errno=ENOMEM;
 		return(-1);
 	}
@@ -255,13 +255,10 @@ int recvfilesocket(int sock, int file, long *offset, long count)
 			return(-1);
 
 	rd=read(sock,buf,count);
-	if(rd!=count) {
-		free(buf);
+	if(rd!=count)
 		return(-1);
-	}
 
 	wr=write(file,buf,rd);
-	free(buf);
 
 	if(offset!=NULL)
 		(*offset)+=wr;
diff --git a/src/xpdev/str_list.c b/src/xpdev/str_list.c
index 5cc356434f..cf7c3d0126 100644
--- a/src/xpdev/str_list.c
+++ b/src/xpdev/str_list.c
@@ -366,7 +366,7 @@ static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_l
 
 	count=strListCount(*lp);
 	while(!feof(fp)) {
-		if(buf==NULL && (buf=(char*)malloc(max_line_len+1))==NULL)
+		if(buf==NULL && (buf=(char*)alloca(max_line_len+1))==NULL)
 			return(NULL);
 		
 		if(fgets(buf,max_line_len+1,fp)==NULL)
@@ -374,9 +374,6 @@ static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_l
 		strListAppend(lp, buf, count++);
 	}
 
-	if(buf!=NULL)
-		free(buf);
-
 	return(*lp);
 }
 
-- 
GitLab