question relating to the memory deallocation
Status: Beta
Brought to you by:
rlaager
From: Ivan P. <iva...@bu...> - 2011-02-01 21:50:39
|
I noticed that docsis utility leaks memory when it is used with option -m ( multiple cable modem configuration files) I suppose that TLV nodes shoud be deallocated before next iteration. tlvtreelen function could be used for deallocation. For example : void tlvtree_dealloc(struct tlv *tlv) { struct tlv *tlvptr; struct tlv *tlvptr_left; unsigned int current_size = 0; if (tlv == NULL)return ; tlvptr=tlv; while (tlvptr) { if (tlvptr->first_child) { tlvtree_dealloc(tlvptr->first_child); } tlvptr_left = tlvptr; tlvptr = tlvptr->next_sibling; free (tlvptr_left); } } and some minor changes to parse_config_file function int parse_config_file(char *file, struct tlv **parse_tree_result) { FILE *cf; int rval; if (_my_tlvtree_head) { tlvtree_dealloc(_my_tlvtree_head); _my_tlvtree_head=NULL; } if ((cf = fopen(file, "r")) == NULL) { printf("%s: Can't open input file %s Error -> %s %i \n", prog_name, file, strerror(errno), errno); return -1; } ... ... } Best regards , Ivan Prostran |