Skip to content

Commit d78ca8c

Browse files
committed
fix mem leaks
1 parent b1f3569 commit d78ca8c

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

ext-src/swoole_table.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ static void inline php_swoole_table_set_ptr(zval *zobject, Table *ptr) {
109109
}
110110

111111
static inline void php_swoole_table_free_object(zend_object *object) {
112+
Table *table = php_swoole_table_fetch_object(object)->ptr;
113+
if (table) {
114+
table->free();
115+
}
112116
zend_object_std_dtor(object);
113117
}
114118

include/swoole_table.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ class Table {
162162
TableRow *get(const char *key, uint16_t keylen, TableRow **rowlock);
163163
bool del(const char *key, uint16_t keylen);
164164
void forward();
165+
// only release local memory of the current process
166+
void free();
167+
// release shared memory
165168
void destroy();
166169

167170
bool is_created() {

src/memory/table.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ Table *Table::make(uint32_t rows_size, float conflict_proportion) {
5757
return table;
5858
}
5959

60+
void Table::free() {
61+
delete mutex;
62+
delete iterator;
63+
delete column_map;
64+
delete column_list;
65+
}
66+
6067
bool Table::add_column(const std::string &_name, enum TableColumn::Type _type, size_t _size) {
6168
if (_type < TableColumn::TYPE_INT || _type > TableColumn::TYPE_STRING) {
6269
swWarn("unknown column type");

0 commit comments

Comments
 (0)