Skip to content

fix: memory leak at msc_tree #3428

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/utils/msc_tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,10 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
CPTData *prefix_data = CPTCreateCPTData(netmask);
CPTAppendToCPTDataList(prefix_data, &prefix->prefix_data);

if(CheckBitmask(netmask, ip_bitmask))
if(CheckBitmask(netmask, ip_bitmask)) {
free(prefix);
return node;
}

parent = node->parent;
while (parent != NULL && netmask < (parent->bit + 1)) {
Expand All @@ -423,6 +425,7 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree

if ((node->count -1) == 0) {
node->netmasks[0] = netmask;
free(prefix);
return new_node;
}

Expand All @@ -449,8 +452,10 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree

new_node = CPTCreateNode();

if(new_node == NULL)
if(new_node == NULL) {
free(prefix);
return NULL;
}

new_node->prefix = prefix;
new_node->bit = prefix->bitlen;
Expand Down
Loading