Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Potential memory leak in hlindex_open when open_table_from_share fails

Đang mở
#152 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@JoeJRW đang làm issue này rồi.

Từ ngày 18/5/2026.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

bug

In sql/vidx/vidx_index.cc, the hlindex_open function allocates memory for hlindex with my_malloc() at line 980, and increments s->hlindex->ref_count() at lines 988-990 before calling open_table_from_share().

However, when open_table_from_share() fails (error != 0), the function jumps to error_end at line 1001 without:

Decrementing the ref_count that was previously incremented
Freeing the allocated hlindex memory
Code location :

// Line 980: Allocate hlindex
hlindex = (TABLE *)my_malloc(key_memory_TABLE, sizeof(*hlindex), MYF(MY_WME));

// Lines 987-990: Increment ref_count
if (s->hlindex->tmp_table == NO_TMP_TABLE) {
mysql_mutex_lock(&LOCK_open);
s->hlindex->increment_ref_count();
mysql_mutex_unlock(&LOCK_open);
}

// Lines 993-997: Call open_table_from_share
int error = open_table_from_share(in_use, s->hlindex, hlindex_name,
(uint)(HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
HA_GET_INDEX | HA_TRY_READ_ONLY),
EXTRA_RECORD, in_use->open_options,
hlindex, false, hlindex_dd);

// Lines 999-1001: Problem: When error != 0, no cleanup before goto error_end
if (error != 0 || hlindex == nullptr) {
error_message = "Failed to open_table_from_share.";
goto error_end; // Memory leak here!
}

Note: open_table_from_share() does NOT free the passed outparam pointer on failure (verified in sql/table.cc). It only cleans internal resources.

Suggested fix:

if (error != 0 || hlindex == nullptr) {
error_message = "Failed to open_table_from_share.";
if (hlindex != nullptr) {
if (s->hlindex->tmp_table == NO_TMP_TABLE) {
mysql_mutex_lock(&LOCK_open);
s->hlindex->decrement_ref_count();
mysql_mutex_unlock(&LOCK_open);
}
my_free(hlindex);
hlindex = nullptr;
}
goto error_end;
}

Ngôn ngữ chính
C++
Star
6k
Fork
903
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của alibaba/AliSQL

Tất cả issue của alibaba/AliSQL

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.