IpAddrSet *IpAddrSetCopy(IpAddrSet *ipAddrSet) { IpAddrSet *newIpAddrSet = NULL; IpAddrSet *current = NULL; IpAddrSet *prev = NULL; while(ipAddrSet) { if(!(current = (IpAddrSet *)malloc(sizeof(IpAddrSet)))) { /* ENOMEM */ goto failed; } current->ip_addr = ipAddrSet->ip_addr; current->netmask = ipAddrSet->netmask; current->addr_flags = ipAddrSet->addr_flags; current->next = NULL; if(!prev) newIpAddrSet = current; else prev->next = current; ipAddrSet = ipAddrSet->next; prev = current; } return newIpAddrSet; failed: if(newIpAddrSet) IpAddrSetDestroy(newIpAddrSet); return NULL; /* XXX ENOMEM */ }
static void SFRF_ConfigNodeFree(void *item) { tSFRFConfigNode *node = (tSFRFConfigNode *)item; if (node == NULL) return; if (node->applyTo != NULL) { IpAddrSetDestroy(node->applyTo); } free(node); }
static void sfthd_node_free(void *node) { THD_NODE *sfthd_node = (THD_NODE *)node; if (sfthd_node == NULL) return; if (sfthd_node->ip_address != NULL) { IpAddrSetDestroy(sfthd_node->ip_address); } free(sfthd_node); }
IpAddrSet *IpAddrSetCopy(IpAddrSet *ipAddrSet) { IpAddrSet *newIpAddrSet; IpAddrNode *current; IpAddrNode *iplist, *neglist; IpAddrNode *prev = NULL; if(!ipAddrSet) return NULL; newIpAddrSet = (IpAddrSet *)calloc(sizeof(IpAddrSet), 1); if(!newIpAddrSet) { goto failed; } iplist = ipAddrSet->iplist; neglist = ipAddrSet->neg_iplist; while(iplist) { current = (IpAddrNode *)malloc(sizeof(IpAddrNode)); if (!current) { goto failed; } if(!newIpAddrSet->iplist) newIpAddrSet->iplist = current; current->ip_addr = iplist->ip_addr; current->netmask = iplist->netmask; current->addr_flags = iplist->addr_flags; current->next = NULL; if(prev) prev->next = current; prev = current; iplist = iplist->next; } prev = current = NULL; while(neglist) { current = (IpAddrNode *)malloc(sizeof(IpAddrNode)); if (!current) { goto failed; } if(!newIpAddrSet->neg_iplist) newIpAddrSet->neg_iplist = current; current->ip_addr = neglist->ip_addr; current->netmask = neglist->netmask; current->addr_flags = neglist->addr_flags; current->next = NULL; if(prev) prev->next = current; prev = current; neglist = neglist->next; } newIpAddrSet->id = ipAddrSet->id; return newIpAddrSet; failed: if(newIpAddrSet) IpAddrSetDestroy(newIpAddrSet); return NULL; /* XXX ENOMEM */ }