Skip to content

Commit

Permalink
fix mem leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Mar 5, 2021
1 parent b1f3569 commit d78ca8c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext-src/swoole_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ static void inline php_swoole_table_set_ptr(zval *zobject, Table *ptr) {
}

static inline void php_swoole_table_free_object(zend_object *object) {
Table *table = php_swoole_table_fetch_object(object)->ptr;
if (table) {
table->free();
}
zend_object_std_dtor(object);
}

Expand Down
3 changes: 3 additions & 0 deletions include/swoole_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ class Table {
TableRow *get(const char *key, uint16_t keylen, TableRow **rowlock);
bool del(const char *key, uint16_t keylen);
void forward();
// only release local memory of the current process
void free();
// release shared memory
void destroy();

bool is_created() {
Expand Down
7 changes: 7 additions & 0 deletions src/memory/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Table *Table::make(uint32_t rows_size, float conflict_proportion) {
return table;
}

void Table::free() {
delete mutex;
delete iterator;
delete column_map;
delete column_list;
}

bool Table::add_column(const std::string &_name, enum TableColumn::Type _type, size_t _size) {
if (_type < TableColumn::TYPE_INT || _type > TableColumn::TYPE_STRING) {
swWarn("unknown column type");
Expand Down

0 comments on commit d78ca8c

Please sign in to comment.