fix memory leak bug

This commit is contained in:
Xuan Sang LE 2018-03-14 11:55:15 +01:00
parent 5f12b8917a
commit 4679f6ab04
2 changed files with 12 additions and 5 deletions

View File

@ -19,8 +19,13 @@ void accept_request(void* client)
//char *query_string = NULL;
//LOG("SOCK IS %d\n", ((antd_client_t*)client)->sock);
numchars = read_buf(client, buf, sizeof(buf));
if(numchars < 0)
{
unknow(client);
goto end;
}
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];
i++; j++;
@ -108,7 +113,9 @@ void accept_request(void* client)
char* mime_type = mime(path);
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)
{
sprintf(buf,"/%s%s",h,url);

View File

@ -81,11 +81,11 @@ char* __s(const char* fstring,...)
*/
void trim(char* str, const char delim)
{
if(!str) return;
if(!str || strlen(str) == 0) return;
char * p = str;
int l = strlen(p);
while(p[l - 1] == delim) p[--l] = 0;
while(l > 0 && p[l - 1] == delim)
p[--l] = 0;
while(* p && (* p) == delim ) ++p, --l;
memmove(str, p, l + 1);
}