Commit da0168a3 authored by zhujiashun's avatar zhujiashun

redis_server_protocol: fix mem leak

parent c9cb309a
...@@ -80,6 +80,9 @@ public: ...@@ -80,6 +80,9 @@ public:
class RedisConnContext : public brpc::SharedObject { class RedisConnContext : public brpc::SharedObject {
public: public:
RedisConnContext() : handler_continue(NULL) {} RedisConnContext() : handler_continue(NULL) {}
~RedisConnContext() {
ClearQueue(dones);
}
void Push(ConsumeTaskDone* done) { void Push(ConsumeTaskDone* done) {
std::unique_lock<butil::Mutex> m(_mutex); std::unique_lock<butil::Mutex> m(_mutex);
...@@ -120,9 +123,13 @@ public: ...@@ -120,9 +123,13 @@ public:
ready_to_delete.push(head); ready_to_delete.push(head);
} }
} }
while (!ready_to_delete.empty()) { ClearQueue(ready_to_delete);
ConsumeTaskDone* head = ready_to_delete.front(); }
ready_to_delete.pop();
void ClearQueue(std::queue<ConsumeTaskDone*>& queue) {
while (!queue.empty()) {
ConsumeTaskDone* head = queue.front();
queue.pop();
delete head; delete head;
} }
} }
......
...@@ -375,9 +375,16 @@ void RedisMessage::CopyFromDifferentArena(const RedisMessage& other, ...@@ -375,9 +375,16 @@ void RedisMessage::CopyFromDifferentArena(const RedisMessage& other,
new (&subs[i]) RedisMessage; new (&subs[i]) RedisMessage;
} }
_data.array.last_index = other._data.array.last_index; _data.array.last_index = other._data.array.last_index;
if (_data.array.last_index > 0) {
// incomplete state
for (int i = 0; i < _data.array.last_index; ++i) {
subs[i].CopyFromDifferentArena(other._data.array.replies[i], arena);
}
} else {
for (size_t i = 0; i < _length; ++i) { for (size_t i = 0; i < _length; ++i) {
subs[i].CopyFromDifferentArena(other._data.array.replies[i], arena); subs[i].CopyFromDifferentArena(other._data.array.replies[i], arena);
} }
}
_data.array.replies = subs; _data.array.replies = subs;
} }
break; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment