Commit b545a623 authored by deuce's avatar deuce
Browse files

alloca() considered harmful.

parent 6308ebe8
......@@ -401,8 +401,8 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
return(JS_FALSE);
}
if((buf=alloca(len))==NULL)
return(JS_TRUE);
if((buf=malloc(len))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
if(fgets(buf,len,p->fp)!=NULL) {
......@@ -422,6 +422,7 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
} else {
JS_RESUMEREQUEST(cx, rc);
}
free(buf);
return(JS_TRUE);
}
......
......@@ -3408,7 +3408,7 @@ js_socket_select(JSContext *cx, uintN argc, jsval *arglist)
if((rarray = JS_NewArrayObject(cx, 0, NULL))==NULL)
return(JS_FALSE);
if((index=(SOCKET *)alloca(sizeof(SOCKET)*limit))==NULL)
if((index=(SOCKET *)malloc(sizeof(SOCKET)*limit))==NULL)
return(JS_FALSE);
FD_ZERO(&socket_set);
......@@ -3446,6 +3446,7 @@ js_socket_select(JSContext *cx, uintN argc, jsval *arglist)
JS_SET_RVAL(cx, arglist, OBJECT_TO_JSVAL(rarray));
}
free(index);
JS_RESUMEREQUEST(cx, rc);
return(JS_TRUE);
......
......@@ -340,7 +340,7 @@ js_read(JSContext *cx, uintN argc, jsval *arglist)
if(!JS_ValueToInt32(cx,argv[0],&len))
return JS_FALSE;
}
if((buf=alloca(len))==NULL)
if((buf=malloc(len))==NULL)
return(JS_TRUE);
rc=JS_SUSPENDREQUEST(cx);
......@@ -349,6 +349,7 @@ js_read(JSContext *cx, uintN argc, jsval *arglist)
if(rd>=0)
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyN(cx,buf,rd)));
free(buf);
return(JS_TRUE);
}
......@@ -368,7 +369,7 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
if(!JS_ValueToInt32(cx,argv[0],&len))
return JS_FALSE;
}
if((buf=alloca(len+1))==NULL)
if((buf=malloc(len+1))==NULL)
return(JS_TRUE);
rc=JS_SUSPENDREQUEST(cx);
......@@ -377,6 +378,7 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
if(p!=NULL)
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyZ(cx,truncnl(p))));
free(buf);
return(JS_TRUE);
}
......
......@@ -2359,7 +2359,7 @@ static void smtp_thread(void* arg)
return;
}
if((mailproc_to_match=alloca(sizeof(BOOL)*mailproc_count))==NULL) {
if((mailproc_to_match=malloc(sizeof(BOOL)*mailproc_count))==NULL) {
lprintf(LOG_CRIT,"%04d !SMTP ERROR allocating memory for mailproc_to_match", socket);
sockprintf(socket,sys_error);
mail_close_socket(socket);
......@@ -2416,6 +2416,7 @@ static void smtp_thread(void* arg)
thread_down();
protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
}
......@@ -2428,6 +2429,7 @@ static void smtp_thread(void* arg)
thread_down();
protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
}
......@@ -2448,6 +2450,7 @@ static void smtp_thread(void* arg)
thread_down();
protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
}
}
......@@ -2462,6 +2465,7 @@ static void smtp_thread(void* arg)
thread_down();
protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
}
SAFEPRINTF(spam.file,"%sspam",scfg.data_dir);
......@@ -2485,6 +2489,7 @@ static void smtp_thread(void* arg)
thread_down();
protected_uint32_adjust(&active_clients, -1);
update_clients();
free(mailproc_to_match);
return;
}
......@@ -4079,6 +4084,7 @@ static void smtp_thread(void* arg)
lprintf(LOG_INFO,"%04d SMTP Session thread terminated (%u threads remain, %lu clients served)"
,socket, remain, ++stats.smtp_served);
}
free(mailproc_to_match);
/* Must be last */
mail_close_socket(socket);
......
......@@ -678,6 +678,7 @@ static DWORD get_service_info(SC_HANDLE hSCManager, char* name, DWORD* state)
SC_HANDLE hService;
DWORD size;
DWORD err;
DWORD ret;
SERVICE_STATUS status;
LPQUERY_SERVICE_CONFIG service_config;
......@@ -704,7 +705,7 @@ static DWORD get_service_info(SC_HANDLE hSCManager, char* name, DWORD* state)
if(state!=NULL && QueryServiceStatus(hService,&status))
*state=status.dwCurrentState;
if((service_config=alloca(size))==NULL) {
if((service_config=malloc(size))==NULL) {
printf("\n!ERROR allocating %u bytes of memory\n", size);
return(-1);
}
......@@ -716,11 +717,14 @@ static DWORD get_service_info(SC_HANDLE hSCManager, char* name, DWORD* state)
&size /* address of variable for bytes needed */
)) {
printf("\n!QueryServiceConfig ERROR %u\n",GetLastError());
free(service_config);
return(-1);
}
CloseServiceHandle(hService);
ret=service_config->dwStartType
free(service_config);
return(service_config->dwStartType);
return ret;
}
/****************************************************************************/
......
......@@ -270,8 +270,8 @@ js_read(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
if((buf=alloca(len))==NULL)
return(JS_TRUE);
if((buf=malloc(len))==NULL)
return(JS_FALSE);
rc=JS_SUSPENDREQUEST(cx);
len=recv(client->socket,buf,len,0);
......@@ -279,6 +279,7 @@ js_read(JSContext *cx, uintN argc, jsval *arglist)
if(len>0)
JS_SET_RVAL(cx, arglist, STRING_TO_JSVAL(JS_NewStringCopyN(cx,buf,len)));
free(buf);
return(JS_TRUE);
}
......@@ -308,14 +309,16 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
return JS_FALSE;
}
if((buf=(char*)alloca(len+1))==NULL) {
if((buf=(char*)malloc(len+1))==NULL) {
JS_ReportError(cx,"Error allocating %u bytes",len+1);
return(JS_FALSE);
}
if(argc>1) {
if(!JS_ValueToInt32(cx,argv[1],(int32*)&timeout))
if(!JS_ValueToInt32(cx,argv[1],(int32*)&timeout)) {
free(buf);
return JS_FALSE;
}
}
rc=JS_SUSPENDREQUEST(cx);
......@@ -329,6 +332,7 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
if(time(NULL)-start>timeout) {
JS_SET_RVAL(cx, arglist, JSVAL_NULL);
JS_RESUMEREQUEST(cx, rc);
free(buf);
return(JS_TRUE); /* time-out */
}
continue; /* no data */
......@@ -349,6 +353,7 @@ js_readln(JSContext *cx, uintN argc, jsval *arglist)
JS_RESUMEREQUEST(cx, rc);
str = JS_NewStringCopyZ(cx, buf);
free(buf);
if(str==NULL)
return(JS_FALSE);
......
......@@ -665,16 +665,13 @@ static void add_env(http_session_t *session, const char *name,const char *value)
if(*p=='-')
*p='_';
}
p=(char *)alloca(strlen(name)+strlen(value)+2);
p=xp_asprintf("%s=%s",newname,value);
if(p==NULL) {
lprintf(LOG_WARNING,"%04d Cannot allocate memory for string", session->socket);
return;
}
#if 0 /* this is way too verbose for every request */
lprintf(LOG_DEBUG,"%04d Adding CGI environment variable %s=%s",session->socket,newname,value);
#endif
sprintf(p,"%s=%s",newname,value);
strListPush(&session->req.cgi_env,p);
free(p);
}
/***************************************/
......@@ -1069,7 +1066,7 @@ static BOOL send_headers(http_session_t *session, const char *status, int chunke
session->req.ld->status=atoi(status);
return(TRUE);
}
headers=alloca(MAX_HEADERS_SIZE);
headers=malloc(MAX_HEADERS_SIZE);
if(headers==NULL) {
lprintf(LOG_CRIT,"Could not allocate memory for response headers.");
return(FALSE);
......@@ -1223,6 +1220,7 @@ static BOOL send_headers(http_session_t *session, const char *status, int chunke
send_file = (bufprint(session,headers) && send_file);
drain_outbuf(session);
session->req.write_chunked=chunked;
free(headers);
return(send_file);
}
......@@ -2023,15 +2021,15 @@ static void js_add_header(http_session_t * session, char *key, char *value)
JSString* js_str;
char *lckey;
if((lckey=(char *)alloca(strlen(key)+1))==NULL)
if((lckey=strdup(key))==NULL)
return;
strcpy(lckey,key);
strlwr(lckey);
if((js_str=JS_NewStringCopyZ(session->js_cx, value))==NULL) {
return;
}
JS_DefineProperty(session->js_cx, session->js_header, lckey, STRING_TO_JSVAL(js_str)
,NULL,NULL,JSPROP_ENUMERATE|JSPROP_READONLY);
free(lckey);
}
#if 0
......@@ -5163,7 +5161,7 @@ void http_session_thread(void* arg)
session.last_js_user_num=-1;
session.logon_time=0;
session.subscan=(subscan_t*)alloca(sizeof(subscan_t)*scfg.total_subs);
session.subscan=(subscan_t*)malloc(sizeof(subscan_t)*scfg.total_subs);
while(!session.finished) {
init_error=FALSE;
......@@ -5263,6 +5261,7 @@ void http_session_thread(void* arg)
sem_wait(&session.output_thread_terminated);
sem_destroy(&session.output_thread_terminated);
RingBufDispose(&session.outbuf);
free(session.subscan);
clients_remain=protected_uint32_adjust(&active_clients, -1);
update_clients();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment