r17102 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17101‎ | r17102 | r17103 >
Date:02:24, 19 October 2006
Author:river
Status:old
Tags:
Comment:
less with the leaking of memory
add header freelist
Modified paths:
  • /trunk/willow/src/include/whttp_entity.h (modified) (history)
  • /trunk/willow/src/willow/wbackend.cc (modified) (history)
  • /trunk/willow/src/willow/whttp.cc (modified) (history)
  • /trunk/willow/src/willow/whttp_entity.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/include/whttp_entity.h
@@ -58,8 +58,27 @@
5959 struct header {
6060 header(char *n, char *v)
6161 : hr_name(n), hr_value(v) {}
 62+ header() : hr_name(NULL), hr_value(NULL), fl_next(NULL) {}
6263 char *hr_name;
6364 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;
6483 };
6584
6685 struct header_list {
Index: trunk/willow/src/willow/whttp_entity.cc
@@ -94,6 +94,8 @@
9595 static void entity_send_target_write(struct bufferevent *, void *);
9696 static void entity_send_target_error(struct bufferevent *, short, void *);
9797
 98+header header::hr_fl; /* header free list */
 99+
98100 const char *ent_errors[] = {
99101 /* 0 */ "Unknown error",
100102 /* -1 */ "Read error",
@@ -119,6 +121,7 @@
120122 WDEBUG((WLOG_DEBUG, "free entity @ %p", entity));
121123
122124 header_free(&entity->he_headers);
 125+ entity->he_headers.~header_list();
123126 if (entity->_he_frombuf) {
124127 bufferevent_disable(entity->_he_frombuf, EV_READ | EV_WRITE);
125128 bufferevent_free(entity->_he_frombuf);
@@ -135,7 +138,6 @@
136139 if (entity->he_rdata.request.path)
137140 wfree(entity->he_rdata.request.path);
138141 }
139 - bzero(entity, sizeof(*entity));
140142 }
141143
142144 void
@@ -943,7 +945,6 @@
944946 value = hdr[1];
945947 while (isspace(*value))
946948 ++value;
947 - value = wstrdup(value);
948949
949950 WDEBUG((WLOG_DEBUG, "header: from [%s], [%s] = [%s]",
950951 line, hdr[0], value));
@@ -957,17 +958,17 @@
958959 error = ENT_ERR_INVHOST;
959960 goto error;
960961 }
961 - header_add(&entity->he_headers, wstrdup(hdr[0]), value);
 962+ header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value));
962963 entity->he_rdata.request.host = wstrdup(value);
963964 } 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));
965966 entity->he_rdata.request.contlen = atoi(value);
966967 } else if (!strcasecmp(hdr[0], "Via")) {
967968 if (via_includes_me(value)) {
968969 error = ENT_ERR_LOOP;
969970 goto error;
970971 }
971 - header_add(&entity->he_headers, wstrdup(hdr[0]), value);
 972+ header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value));
972973 } else if (!strcasecmp(hdr[0], "transfer-encoding")) {
973974 /* XXX */
974975 if (!strcasecmp(value, "chunked")) {
@@ -998,7 +999,7 @@
9991000 entity->he_h_last_modified = wstrdup(value);
10001001 header_add(&entity->he_headers, wstrdup(hdr[0]), entity->he_h_last_modified);
10011002 } else
1002 - header_add(&entity->he_headers, wstrdup(hdr[0]), value);
 1003+ header_add(&entity->he_headers, wstrdup(hdr[0]), wstrdup(value));
10031004
10041005 wstrvecfree(hdr);
10051006 break;
Index: trunk/willow/src/willow/whttp.cc
@@ -201,11 +201,10 @@
202202 if (freelist.fe_next) {
203203 cl = freelist.fe_next;
204204 freelist.fe_next = cl->fe_next;
205 - new (cl) http_client;
206205 } else
207 - cl = new http_client;
208 -
 206+ cl = (http_client *)new char[sizeof(http_client)];
209207 memset(cl, 0, sizeof(*cl));
 208+ new (cl) http_client;
210209 cl->cl_fde = e;
211210 return cl;
212211 }
Index: trunk/willow/src/willow/wbackend.cc
@@ -178,7 +178,7 @@
179179 wnet_register(e->fde_fd, FDE_WRITE, NULL, NULL);
180180
181181 cbd->bc_func(cbd->bc_backend, e, cbd->bc_data);
182 - wfree(cbd);
 182+ delete cbd;
183183 }
184184
185185 static struct backend *