diff options
-rw-r--r-- | ot_http.c | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -32,7 +32,7 @@ | |||
32 | #include "trackerlogic.h" | 32 | #include "trackerlogic.h" |
33 | 33 | ||
34 | #ifdef WANT_NO_AUTO_FREE | 34 | #ifdef WANT_NO_AUTO_FREE |
35 | #define OT_IOB_INIT(B) bzero(B, sizeof(io_batch)) | 35 | #define OT_IOB_INIT(B) (bzero(B, sizeof(io_batch)), 0) |
36 | #else | 36 | #else |
37 | #define OT_IOB_INIT(B) iob_init_autofree(B, 0) | 37 | #define OT_IOB_INIT(B) iob_init_autofree(B, 0) |
38 | #endif | 38 | #endif |
@@ -88,7 +88,15 @@ static void http_senddata(const int64 sock, struct ot_workstruct *ws) { | |||
88 | memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); | 88 | memcpy(outbuf, ws->reply + written_size, ws->reply_size - written_size); |
89 | if (!cookie->batch) { | 89 | if (!cookie->batch) { |
90 | cookie->batch = malloc(sizeof(io_batch)); | 90 | cookie->batch = malloc(sizeof(io_batch)); |
91 | OT_IOB_INIT(cookie->batch); | 91 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
92 | free(cookie->batch); | ||
93 | free(outbuf); | ||
94 | array_reset(&cookie->request); | ||
95 | free(cookie); | ||
96 | io_close(sock); | ||
97 | return; | ||
98 | } | ||
99 | |||
92 | cookie->batches = 1; | 100 | cookie->batches = 1; |
93 | } | 101 | } |
94 | 102 | ||
@@ -183,12 +191,12 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
183 | 191 | ||
184 | if (!cookie->batch) { | 192 | if (!cookie->batch) { |
185 | cookie->batch = malloc(sizeof(io_batch)); | 193 | cookie->batch = malloc(sizeof(io_batch)); |
186 | if (!cookie->batch) { | 194 | if (!cookie->batch || OT_IOB_INIT(cookie->batch) == -1) { |
195 | free(cookie->batch); | ||
187 | free(header); | 196 | free(header); |
188 | iovec_free(&iovec_entries, &iovector); | 197 | iovec_free(&iovec_entries, &iovector); |
189 | HTTPERROR_500; | 198 | HTTPERROR_500; |
190 | } | 199 | } |
191 | OT_IOB_INIT(cookie->batch); | ||
192 | cookie->batches = 1; | 200 | cookie->batches = 1; |
193 | } | 201 | } |
194 | current = cookie->batch + cookie->batches - 1; | 202 | current = cookie->batch + cookie->batches - 1; |
@@ -201,8 +209,8 @@ ssize_t http_sendiovecdata(const int64 sock, struct ot_workstruct *ws, int iovec | |||
201 | io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); | 209 | io_batch *new_batch = realloc(cookie->batch, (cookie->batches + 1) * sizeof(io_batch)); |
202 | if (new_batch) { | 210 | if (new_batch) { |
203 | cookie->batch = new_batch; | 211 | cookie->batch = new_batch; |
204 | current = cookie->batch + cookie->batches++; | 212 | if (OT_IOB_INIT(current) != -1) |
205 | OT_IOB_INIT(current); | 213 | current = cookie->batch + cookie->batches++; |
206 | } | 214 | } |
207 | } | 215 | } |
208 | iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); | 216 | iob_addbuf_free(current, iovector[i].iov_base, iovector[i].iov_len); |