mirror of
				https://github.com/lxsang/ant-http
				synced 2025-10-31 10:25:55 +01:00 
			
		
		
		
	fix memory leak bug
This commit is contained in:
		| @@ -19,8 +19,13 @@ void accept_request(void* client) | |||||||
| 	//char *query_string = NULL; | 	//char *query_string = NULL; | ||||||
| 	//LOG("SOCK IS %d\n", ((antd_client_t*)client)->sock); | 	//LOG("SOCK IS %d\n", ((antd_client_t*)client)->sock); | ||||||
| 	numchars = read_buf(client, buf, sizeof(buf)); | 	numchars = read_buf(client, buf, sizeof(buf)); | ||||||
|  | 	if(numchars < 0) | ||||||
|  | 	{ | ||||||
|  | 		unknow(client);  | ||||||
|  | 		goto end; | ||||||
|  | 	} | ||||||
| 	i = 0; j = 0; | 	i = 0; j = 0; | ||||||
| 	while (!ISspace(buf[j]) && (i < sizeof(method) - 1)) | 	while (j < numchars && !ISspace(buf[j]) && (i < sizeof(method) - 1)) | ||||||
| 	{ | 	{ | ||||||
| 		method[i] = buf[j]; | 		method[i] = buf[j]; | ||||||
| 		i++; j++; | 		i++; j++; | ||||||
| @@ -108,7 +113,9 @@ void accept_request(void* client) | |||||||
| 		char* mime_type = mime(path); | 		char* mime_type = mime(path); | ||||||
| 		if(strcmp(mime_type,"application/octet-stream") == 0) | 		if(strcmp(mime_type,"application/octet-stream") == 0) | ||||||
| 		{ | 		{ | ||||||
| 			char* h = dvalue(server_config.handlers,ext(path)); | 			char * ex = ext(path); | ||||||
|  | 			char* h = dvalue(server_config.handlers,ex); | ||||||
|  | 			if(ex) free(ex); | ||||||
| 			if(h) | 			if(h) | ||||||
| 			{ | 			{ | ||||||
| 				sprintf(buf,"/%s%s",h,url); | 				sprintf(buf,"/%s%s",h,url); | ||||||
|   | |||||||
| @@ -81,11 +81,11 @@ char* __s(const char* fstring,...) | |||||||
|  */ |  */ | ||||||
| void trim(char* str, const char delim) | void trim(char* str, const char delim) | ||||||
| { | { | ||||||
|     if(!str) return; |     if(!str || strlen(str) == 0) return; | ||||||
|     char * p = str; |     char * p = str; | ||||||
|     int l = strlen(p); |     int l = strlen(p); | ||||||
|  |     while(l > 0 && p[l - 1] == delim) | ||||||
|     while(p[l - 1] == delim) p[--l] = 0; |         p[--l] = 0; | ||||||
|     while(* p && (* p) == delim ) ++p, --l; |     while(* p && (* p) == delim ) ++p, --l; | ||||||
|     memmove(str, p, l + 1); |     memmove(str, p, l + 1); | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user