Skip to content
Snippets Groups Projects
Commit eb46be97 authored by deuce's avatar deuce
Browse files

Use alloca() instead of malloc()/free() where possible.

parent 7a71bb05
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
* Note: If this box doesn't appear square, then you need to fix your tabs. * * 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 <string.h> /* bzero (for FD_ZERO) on FreeBSD */
#include <errno.h> /* ENOMEM */ #include <errno.h> /* ENOMEM */
#include <stdio.h> /* SEEK_SET */ #include <stdio.h> /* SEEK_SET */
...@@ -245,7 +245,7 @@ int recvfilesocket(int sock, int file, long *offset, long count) ...@@ -245,7 +245,7 @@ int recvfilesocket(int sock, int file, long *offset, long count)
return(-1); return(-1);
} }
if((buf=(char*)malloc(count))==NULL) { if((buf=(char*)alloca(count))==NULL) {
errno=ENOMEM; errno=ENOMEM;
return(-1); return(-1);
} }
...@@ -255,13 +255,10 @@ int recvfilesocket(int sock, int file, long *offset, long count) ...@@ -255,13 +255,10 @@ int recvfilesocket(int sock, int file, long *offset, long count)
return(-1); return(-1);
rd=read(sock,buf,count); rd=read(sock,buf,count);
if(rd!=count) { if(rd!=count)
free(buf);
return(-1); return(-1);
}
wr=write(file,buf,rd); wr=write(file,buf,rd);
free(buf);
if(offset!=NULL) if(offset!=NULL)
(*offset)+=wr; (*offset)+=wr;
......
...@@ -366,7 +366,7 @@ static str_list_t str_list_read_file(FILE* fp, str_list_t* lp, size_t max_line_l ...@@ -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); count=strListCount(*lp);
while(!feof(fp)) { 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); return(NULL);
if(fgets(buf,max_line_len+1,fp)==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 ...@@ -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++); strListAppend(lp, buf, count++);
} }
if(buf!=NULL)
free(buf);
return(*lp); return(*lp);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment