Skip to content

Commit 97c18bf

Browse files
committed
FIX | memory leak
1 parent 66f0e1e commit 97c18bf

File tree

2 files changed

+20
-40
lines changed

2 files changed

+20
-40
lines changed

src/worker/ManapiTcp.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -822,13 +822,6 @@ int manapi::net::worker::TCP::flush_write_(const worker::shared_conn &connection
822822
manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "TCP:packets(%d) were sent %p. now=%d",
823823
nbuff, connection.get(), conn->top->send_size);
824824

825-
if ((conn->flags & (ev::WRITE|ev::DISCONNECT)) == ev::WRITE && conn->ev_callback) {
826-
if (base::call_user_callback(&conn->ev_callback, connection, ev::WRITE, nullptr, 0, nullptr)) {
827-
conn->worker->close_connection(connection, CLOSE_CONN_ERR);
828-
return;
829-
}
830-
}
831-
832825
if (conn->flags & ev::DISCONNECT) {
833826
conn->worker->close_connection(connection, CLOSE_CONN_SHUTDOWN);
834827
return;
@@ -839,6 +832,13 @@ int manapi::net::worker::TCP::flush_write_(const worker::shared_conn &connection
839832
return;
840833
}
841834

835+
if (conn->flags & ev::WRITE && conn->ev_callback) {
836+
if (base::call_user_callback(&conn->ev_callback, connection, ev::WRITE, nullptr, 0, nullptr)) {
837+
conn->worker->close_connection(connection, CLOSE_CONN_ERR);
838+
return;
839+
}
840+
}
841+
842842
if ((conn->flags & CONN_SEND_END) && (conn->flags & CONN_RECV_END)) {
843843
manapi_log_trace(manapi::debug::LOG_TRACE_LOW, "TCP:packets(%d) were sent after closing conn %p. now=%d",
844844
nbuff, connection.get(), conn->top->send_size);

src/worker/ManapiTlsOverTcp.cpp

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,14 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
136136
if (connection->flags & (ev::DISCONNECT))
137137
return -1;
138138

139+
this->ssl_bio_flush_write_(conn, connection, maxcnt, false);
140+
139141
char buffer[32768];
140142
int cursor = 0;
141143
size_t lastcur = 0;
142144
ssize_t total = 0;
143145

146+
144147
while (nbuff) {
145148
if (connection->top->send_size > maxcnt)
146149
break;
@@ -175,37 +178,25 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
175178
rhs = this->ssl_write_(connection->ssl, buffer + current,
176179
static_cast<int>(cursor - current));
177180

178-
if (rhs > 0) {
179-
current += rhs;
181+
if (int erhs = this->ssl_bio_flush_write_(conn, connection, maxcnt, false)) {
182+
if (erhs == CONN_IO_WANT_WRITE) {
183+
if (this->flush_write_(conn, true))
184+
return CONN_IO_ERROR;
185+
return total + current;
186+
}
180187

181-
if (int erhs = this->ssl_bio_flush_write_(conn, connection, maxcnt, false)) {
182-
if (erhs == CONN_IO_WANT_WRITE) {
183-
if (this->flush_write_(conn, true))
184-
return CONN_IO_ERROR;
185-
return total + current;
186-
}
188+
return CONN_IO_ERROR;
189+
}
187190

188-
return CONN_IO_ERROR;
189-
}
191+
if (rhs > 0) {
192+
current += rhs;
190193
}
191194
else {
192195
int err = this->ssl_get_error_(connection->ssl, rhs);
193196

194197
if (err) {
195198
if (err == this->ssl_error_want_read_
196199
|| err == this->ssl_error_want_write_) {
197-
auto const erhs = this->ssl_bio_flush_write_(conn, connection, maxcnt, false);
198-
199-
if (erhs) {
200-
if (erhs == CONN_IO_WANT_WRITE) {
201-
if (this->flush_write_(conn, true))
202-
return CONN_IO_ERROR;
203-
return total + current;
204-
}
205-
206-
return CONN_IO_ERROR;
207-
}
208-
209200
if (this->flush_write_(conn, true))
210201
return CONN_IO_ERROR;
211202

@@ -237,17 +228,6 @@ ssize_t manapi::net::worker::TLS::sync_write_ex(const shared_conn &conn, ev::buf
237228

238229

239230
bool const cfinish = finish && total == size;
240-
auto const err = this->ssl_bio_flush_write_(conn, connection, maxcnt, false);
241-
242-
if (err) {
243-
if (err == CONN_IO_WANT_WRITE) {
244-
if (this->flush_write_(conn, true))
245-
return CONN_IO_ERROR;
246-
return total;
247-
}
248-
249-
return CONN_IO_ERROR;
250-
}
251231

252232
if (this->flush_write_(conn, cfinish))
253233
return CONN_IO_ERROR;

0 commit comments

Comments
 (0)