-
Notifications
You must be signed in to change notification settings - Fork 5k
fix: improve memory handling in cloneVgroups function #34164
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?
Conversation
Summary of ChangesHello @yihaoDeng, 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 focuses on enhancing the memory handling within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 pull request improves memory handling in the cloneVgroups function by adding defensive NULL pointer checks and preventing memory leaks through proper cleanup of previous allocations.
- Added NULL check for the
pDstparameter to prevent dereferencing a NULL pointer - Implemented automatic cleanup of existing memory at
*pDstbefore allocating new memory - Improved code style consistency by standardizing NULL comparison format
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| static int32_t cloneVgroups(SVgroupsInfo** pDst, SVgroupsInfo* pSrc) { | ||
| if (pDst == NULL) return terrno; |
Copilot
AI
Jan 5, 2026
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 error return on line 5716 returns terrno when pDst is NULL. However, terrno may not be set to an appropriate error code at this point. This should return a meaningful error code like TSDB_CODE_INVALID_PARA or TSDB_CODE_OUT_OF_MEMORY instead of relying on terrno which may contain an unrelated error value from previous operations.
| if (*pDst) taosMemoryFreeClear(*pDst); | ||
|
|
||
| if (pSrc == NULL) { | ||
| *pDst = NULL; | ||
| return TSDB_CODE_SUCCESS; | ||
| } |
Copilot
AI
Jan 5, 2026
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.
Line 5719 frees any existing allocation at *pDst before proceeding. However, if pSrc is NULL (checked on line 5721), the function sets *pDst = NULL and returns success. This creates an inconsistency: if the caller passes a non-NULL *pDst with a valid allocation and pSrc is NULL, the existing allocation is freed and *pDst is set to NULL. While this may be intentional behavior to "clone" a NULL source by clearing the destination, it could also be unexpected. Consider whether the free should only happen when pSrc is not NULL, or document this behavior clearly.
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 improves memory handling in the cloneVgroups function by ensuring that any previously allocated memory is freed before a new allocation, which prevents potential memory leaks. The changes are generally good, but I've identified a potential issue with error handling and a minor redundancy that could be simplified for better code clarity. My comments provide more details.
| } | ||
|
|
||
| static int32_t cloneVgroups(SVgroupsInfo** pDst, SVgroupsInfo* pSrc) { | ||
| if (pDst == NULL) return 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.
Returning the global terrno here is risky. The value of terrno is not guaranteed to be an error code at this point; it might hold a success code from a previous unrelated operation. This could lead to silent failures. It's safer to return a specific error code for an invalid parameter, such as TSDB_CODE_INVALID_PARA.
if (pDst == NULL) return TSDB_CODE_INVALID_PARA;| if (*pDst) taosMemoryFreeClear(*pDst); | ||
|
|
||
| if (pSrc == NULL) { | ||
| *pDst = NULL; |
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.
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.