* MDF [core/sp/supplemental] Handle the case when nni_zalloc fails#592
* MDF [core/sp/supplemental] Handle the case when nni_zalloc fails#592RanMaoyi wants to merge 1 commit intonanomq:mainfrom
Conversation
| 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.
Can you check that using cvector_free to release memory is correct or not ? @JaylinYu
There was a problem hiding this comment.
Have you noticed any issues with cvector_free?
There was a problem hiding this comment.
I haven't had any issues yet.
Just curious about the rationality of this approach :P
There was a problem hiding this comment.
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.
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));
}
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.
Maybe nni_strfree is more proper here.
There was a problem hiding this comment.
fix to nni_strfree
| 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.
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