Skip to content

Commit dc42619

Browse files
committed
fix: malloc checks at msc_tree
1 parent 08b70e0 commit dc42619

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/utils/msc_tree.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,9 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
419419
node->count++;
420420
new_node = node;
421421
node->netmasks = reinterpret_cast<unsigned char *>(malloc(node->count * sizeof(unsigned char)));
422+
if (node->netmasks == NULL) {
423+
return node;
424+
}
422425
memset(node->netmasks, 0, (node->count * sizeof(unsigned char)));
423426

424427
if ((node->count -1) == 0) {
@@ -491,15 +494,15 @@ TreeNode *CPTAddElement(unsigned char *ipdata, unsigned int ip_bitmask, CPTTree
491494
}
492495

493496
i_node->netmasks = reinterpret_cast<unsigned char *>(malloc((node->count - i) * sizeof(unsigned char)));
494-
memset(i_node->netmasks, 0, ((node->count - i) * sizeof(unsigned char)));
495-
496497
if(i_node->netmasks == NULL) {
497498
free(new_node->prefix);
498499
free(new_node);
499500
free(i_node);
500501
return NULL;
501502
}
502503

504+
memset(i_node->netmasks, 0, ((node->count - i) * sizeof(unsigned char)));
505+
503506
j = 0;
504507
while (j < (node->count - i)) {
505508
i_node->netmasks[j] = node->netmasks[i + j];

0 commit comments

Comments
 (0)