-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: memleak in getTableList #33818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: memleak in getTableList #33818
Conversation
Summary of ChangesHello @Tony2h, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request primarily resolves a memory leak within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a memory leak in the getTableList function that occurred when attempting to add duplicate entries to the normal tag filter cache. The leak happened because metaUidFilterCachePut returned TSDB_CODE_DUP_KEY without freeing the allocated payload, and the caller didn't handle this case properly.
Key changes:
- Fixed memory leak by properly freeing
pPayloadwhen cache insertion fails, including the duplicate key scenario - Updated
metaUidFilterCachePutto returnTSDB_CODE_DUP_KEYinstead ofTSDB_CODE_SUCCESSwhen duplicate is detected, allowing caller to handle it appropriately - Enhanced log messages with additional context (idstr, origin keys) for better debugging
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| source/libs/executor/src/executil.c | Added error handling to free pPayload when putCachedTableList fails, treating DUP_KEY as success after cleanup; improved log messages with additional debug context |
| source/dnode/vnode/src/meta/metaCache.c | Changed return code from SUCCESS to DUP_KEY when duplicate entry is detected, enabling proper cleanup by caller; added debug logging for cache eviction |
| test/cases/18-StreamProcessing/99-Others/test_stream_tag_cache.py | Updated test to enable metaDebugFlag and adjusted log message patterns to match new log format in C code |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
source/libs/executor/src/executil.c
Outdated
| if (tmp == NULL) { | ||
| taosMemFreeClear(pPayload); | ||
| } | ||
| QUERY_CHECK_NULL(tmp, code, lino, _end, terrno); |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here is problematic. After checking if tmp == NULL and freeing pPayload, the code still executes QUERY_CHECK_NULL(tmp, ...) which will unconditionally jump to _end label when tmp is NULL. This creates unreachable code and a confusing control flow.
If tmp is NULL, the code should either:
- Free pPayload and return/goto immediately without the second check, or
- Only use QUERY_CHECK_NULL without the manual NULL check and free
Suggestion: Remove the manual NULL check and free, and let QUERY_CHECK_NULL handle it by jumping to _end, then ensure cleanup happens at the _end label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
source/libs/executor/src/executil.c
Outdated
| qInfo("suid:%" PRIu64 ", %s add uid list to normal tag filter cache, " | ||
| "uidListSize:%d", pScanNode->suid, idstr, | ||
| (int32_t)taosArrayGetSize(pUidList)); | ||
| qInfo("%s, suid:%" PRIu64 " add uid list to normal tag filter cache, " |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing comma after suid formatting in log message. The format string should be "suid:%" PRIu64 ", add uid list to normal tag filter cache" to match the consistent formatting pattern used in line 2230.
| qInfo("%s, suid:%" PRIu64 " add uid list to normal tag filter cache, " | |
| qInfo("%s, suid:%" PRIu64 ", add uid list to normal tag filter cache, " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request fixes a memory leak in the getTableList function by ensuring that allocated memory for pPayload is freed in all error paths. The changes also involve improving log messages for better debugging and adjusting the return value for duplicate keys in the cache. While the memory leak fix is correct, there's an opportunity to refactor the error handling for better code clarity and to remove redundant checks. Overall, the changes are beneficial and address the reported issue.
source/libs/executor/src/executil.c
Outdated
| if (tmp == NULL) { | ||
| taosMemFreeClear(pPayload); | ||
| } | ||
| QUERY_CHECK_NULL(tmp, code, lino, _end, terrno); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While adding if (tmp == NULL) to free pPayload correctly fixes a potential memory leak, the check is redundant since QUERY_CHECK_NULL on the next line performs the same null check. This can be simplified by handling the NULL case in a single block and then jumping to the error handling label.
if (taosArrayGet(pUidList, 0) == NULL) {
taosMemFreeClear(pPayload);
code = terrno;
lino = __LINE__;
goto _end;
}
void* tmp = taosArrayGet(pUidList, 0);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
source/libs/executor/src/executil.c
Outdated
| pPayload, size, 1); | ||
| QUERY_CHECK_CODE(code, lino, _error); | ||
| if (TSDB_CODE_DUP_KEY == code) { | ||
| code = TSDB_CODE_SUCCESS; // ignore duplicate key error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DUP_KEY时没有释放payload
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修复
…etting pPayload and handling duplicate key errors
Description
Please briefly describe the code changes in this pull request.
Jira: https://jira.taosdata.com:18080/browse/TD-
Checklist
Please check the items in the checklist if applicable.