-
Notifications
You must be signed in to change notification settings - Fork 20
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
* MDF [core/sp/supplemental] Handle the case when nni_zalloc fails #592
base: main
Are you sure you want to change the base?
Conversation
@@ -199,6 +228,12 @@ dbtree_get_tree(dbtree *db, void *(*cb)(uint32_t pipe_id)) | |||
dbtree_info **ret_line_ping = NULL; | |||
for (size_t i = 0; i < cvector_size(nodes); i++) { | |||
dbtree_info *vn = nni_zalloc(sizeof(dbtree_info)); | |||
if (vn == NULL) { | |||
/* All vn are pushed in ret_line_ping vector*/ | |||
cvector_free(ret_line_ping); |
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.
Can you check that using cvector_free to release memory is correct or not ? @JaylinYu
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.
doesnt need this?
@lee-emqx
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.
Have you noticed any issues with cvector_free?
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.
I haven't had any issues yet.
Just curious about the rationality of this approach :P
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.
When dealing with pointer arrays such as ret_line_ping, it's important to remember to free its members before freeing the array itself (use cvector_free). This ensures that memory is properly deallocated and avoids any potential issues.
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.
I just looked at the cvector_free function and did not free all the members, so I added the following code. @JaylinYu @lee-emqx
for (int j = 0; j < cvector_size(ret_line_ping); j++) {
nni_free(ret_line_ping[j], sizeof(dbtree_info));
}
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.
vn's member also need :P
src/supplemental/nanolib/mqtt_db.c
Outdated
* Use free() to release memory, because of the len | ||
* is too difficult to obtain. | ||
*/ | ||
free(topic_queue[i]); |
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.
Maybe nni_strfree is more proper here.
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.
fix to nni_strfree
@@ -199,6 +228,12 @@ dbtree_get_tree(dbtree *db, void *(*cb)(uint32_t pipe_id)) | |||
dbtree_info **ret_line_ping = NULL; | |||
for (size_t i = 0; i < cvector_size(nodes); i++) { | |||
dbtree_info *vn = nni_zalloc(sizeof(dbtree_info)); | |||
if (vn == NULL) { | |||
/* All vn are pushed in ret_line_ping vector*/ | |||
cvector_free(ret_line_ping); |
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.
When dealing with pointer arrays such as ret_line_ping, it's important to remember to free its members before freeing the array itself (use cvector_free). This ensures that memory is properly deallocated and avoids any potential issues.
fixes #589