Commit 3dac803c4158c56bde557910ae93abbd7097a1fa

Authored by Georg Hopp
1 parent 459ecc5d

fix memory leak created while changing things

@@ -31,11 +31,11 @@ char * @@ -31,11 +31,11 @@ char *
31 httpHeaderGet(const HttpHeader header[], int nheader, const char * name) 31 httpHeaderGet(const HttpHeader header[], int nheader, const char * name)
32 { 32 {
33 unsigned long hash = sdbm((unsigned char *)name); 33 unsigned long hash = sdbm((unsigned char *)name);
34 - HttpHeader found; 34 + HttpHeader * found;
35 35
36 found = bsearch(&hash, header, nheader, sizeof(HttpHeader), comp); 36 found = bsearch(&hash, header, nheader, sizeof(HttpHeader), comp);
37 37
38 - return (NULL != found)? found->value : NULL; 38 + return (NULL != *found)? (*found)->value : NULL;
39 } 39 }
40 40
41 // vim: set ts=4 sw=4: 41 // vim: set ts=4 sw=4:
@@ -9,7 +9,7 @@ httpRequestParserGetHeader(HttpRequest request, char * line) @@ -9,7 +9,7 @@ httpRequestParserGetHeader(HttpRequest request, char * line)
9 char * name = line; 9 char * name = line;
10 char * value = strchr(line, ':'); 10 char * value = strchr(line, ':');
11 11
12 - *value = 0; 12 + *(value++) = 0;
13 for (; *value == ' ' && *value != 0; value++); 13 for (; *value == ' ' && *value != 0; value++);
14 14
15 (request->header)[request->nheader++] = new(HttpHeader, name, value); 15 (request->header)[request->nheader++] = new(HttpHeader, name, value);
@@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
2 #include <socket.h> 2 #include <socket.h>
3 #include <string.h> 3 #include <string.h>
4 4
  5 +#include <sys/time.h>
  6 +#include <sys/resource.h>
  7 +
5 #include "server.h" 8 #include "server.h"
6 #include "logger.h" 9 #include "logger.h"
7 #include "http/request_parser.h" 10 #include "http/request_parser.h"
@@ -13,11 +16,15 @@ @@ -13,11 +16,15 @@
13 int 16 int
14 main() 17 main()
15 { 18 {
  19 + struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
  20 +
16 Logger logger = new(LoggerStderr, LOGGER_ERR); 21 Logger logger = new(LoggerStderr, LOGGER_ERR);
17 HttpRequestParser parser = new(HttpRequestParser); 22 HttpRequestParser parser = new(HttpRequestParser);
18 Server server = new(Server, logger, parser, 11212, SOMAXCONN); 23 Server server = new(Server, logger, parser, 11212, SOMAXCONN);
19 //Server server = new(Server, logger, parser, 11212, 20); 24 //Server server = new(Server, logger, parser, 11212, 20);
20 25
  26 + setrlimit(RLIMIT_CPU, &limit);
  27 +
21 init_signals(); 28 init_signals();
22 serverRun(server); 29 serverRun(server);
23 30
Please register or login to post a comment