Index: trunk/willow/src/include/whttp_entity.h |
— | — | @@ -58,8 +58,27 @@ |
59 | 59 | struct header { |
60 | 60 | header(char *n, char *v) |
61 | 61 | : hr_name(n), hr_value(v) {} |
| 62 | + header() : hr_name(NULL), hr_value(NULL), fl_next(NULL) {} |
62 | 63 | char *hr_name; |
63 | 64 | char *hr_value; |
| 65 | + |
| 66 | + void *operator new(size_t size) { |
| 67 | + if (hr_fl.fl_next) { |
| 68 | + header *ret = hr_fl.fl_next; |
| 69 | + hr_fl.fl_next = hr_fl.fl_next->fl_next; |
| 70 | + return ret; |
| 71 | + } |
| 72 | + return ::new char[sizeof(header)]; |
| 73 | + } |
| 74 | + |
| 75 | + void operator delete(void *p) { |
| 76 | + header *hdr = (header *)p; |
| 77 | + hdr->fl_next = hr_fl.fl_next; |
| 78 | + hr_fl.fl_next = hdr; |
| 79 | + } |
| 80 | + |
| 81 | + header *fl_next; |
| 82 | + static header hr_fl; |
64 | 83 | }; |
65 | 84 | |
66 | 85 | struct header_list { |
Index: trunk/willow/src/willow/whttp_entity.cc |
— | — | @@ -94,6 +94,8 @@ |
95 | 95 | static void entity_send_target_write(struct bufferevent *, void *); |
96 | 96 | static void entity_send_target_error(struct bufferevent *, short, void *); |
97 | 97 | |
| 98 | +header header::hr_fl; /* header free list */ |
| 99 | + |
98 | 100 | const char *ent_errors[] = { |
99 | 101 | /* 0 */ "Unknown error", |
100 | 102 | /* -1 */ "Read error", |
— | — | @@ -119,6 +121,7 @@ |
120 | 122 | WDEBUG((WLOG_DEBUG, "free entity @ %p", entity)); |
121 | 123 | |
122 | 124 | header_free(&entity->he_headers); |
| 125 | + entity->he_headers.~header_list(); |
123 | 126 | if (entity->_he_frombuf) { |
124 | 127 | bufferevent_disable(entity->_he_frombuf, EV_READ | EV_WRITE); |
125 | 128 | bufferevent_free(entity->_he_frombuf); |
— | — | @@ -135,7 +138,6 @@ |
136 | 139 | if (entity->he_rdata.request.path) |
137 | 140 | wfree(entity->he_rdata.request.path); |
138 | 141 | } |
139 | | - bzero(entity, sizeof(*entity)); |
140 | 142 | } |
141 | 143 | |
142 | 144 | void |
— | — | @@ -943,7 +945,6 @@ |
944 | 946 | value = hdr[1]; |
945 | 947 | while (isspace(*value)) |
946 | 948 | ++value; |
947 | | - value = wstrdup(value); |
948 | 949 | |
949 | 950 | WDEBUG((WLOG_DEBUG, "header: from [%s], [%s] = [%s]", |
950 | 951 | line, hdr[0], value)); |
— | — | @@ -957,17 +958,17 @@ |
958 | 959 | error = ENT_ERR_INVHOST; |
959 | 960 | goto error; |
960 | 961 | } |
961 | | - header_add(&entity->he_headers, wstrdup(hdr[0]), value); |
| 962 | + header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value)); |
962 | 963 | entity->he_rdata.request.host = wstrdup(value); |
963 | 964 | } else if (!strcasecmp(hdr[0], "Content-Length")) { |
964 | | - header_add(&entity->he_headers, wstrdup(hdr[0]), value); |
| 965 | + header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value)); |
965 | 966 | entity->he_rdata.request.contlen = atoi(value); |
966 | 967 | } else if (!strcasecmp(hdr[0], "Via")) { |
967 | 968 | if (via_includes_me(value)) { |
968 | 969 | error = ENT_ERR_LOOP; |
969 | 970 | goto error; |
970 | 971 | } |
971 | | - header_add(&entity->he_headers, wstrdup(hdr[0]), value); |
| 972 | + header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value)); |
972 | 973 | } else if (!strcasecmp(hdr[0], "transfer-encoding")) { |
973 | 974 | /* XXX */ |
974 | 975 | if (!strcasecmp(value, "chunked")) { |
— | — | @@ -998,7 +999,7 @@ |
999 | 1000 | entity->he_h_last_modified = wstrdup(value); |
1000 | 1001 | header_add(&entity->he_headers, wstrdup(hdr[0]), entity->he_h_last_modified); |
1001 | 1002 | } else |
1002 | | - header_add(&entity->he_headers, wstrdup(hdr[0]), value); |
| 1003 | + header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value)); |
1003 | 1004 | |
1004 | 1005 | wstrvecfree(hdr); |
1005 | 1006 | break; |
Index: trunk/willow/src/willow/whttp.cc |
— | — | @@ -201,11 +201,10 @@ |
202 | 202 | if (freelist.fe_next) { |
203 | 203 | cl = freelist.fe_next; |
204 | 204 | freelist.fe_next = cl->fe_next; |
205 | | - new (cl) http_client; |
206 | 205 | } else |
207 | | - cl = new http_client; |
208 | | - |
| 206 | + cl = (http_client *)new char[sizeof(http_client)]; |
209 | 207 | memset(cl, 0, sizeof(*cl)); |
| 208 | + new (cl) http_client; |
210 | 209 | cl->cl_fde = e; |
211 | 210 | return cl; |
212 | 211 | } |
Index: trunk/willow/src/willow/wbackend.cc |
— | — | @@ -178,7 +178,7 @@ |
179 | 179 | wnet_register(e->fde_fd, FDE_WRITE, NULL, NULL); |
180 | 180 | |
181 | 181 | cbd->bc_func(cbd->bc_backend, e, cbd->bc_data); |
182 | | - wfree(cbd); |
| 182 | + delete cbd; |
183 | 183 | } |
184 | 184 | |
185 | 185 | static struct backend * |