Memory Leak Reduction
diff --git a/nlsr.c b/nlsr.c
index f865944..d00e4ea 100644
--- a/nlsr.c
+++ b/nlsr.c
@@ -210,7 +210,7 @@
}
add_nbr_to_adl(nbr,0,ip_addr);
-
+ free(ip_addr);
free(nbr->name);
free(nbr);
}
@@ -478,7 +478,8 @@
printf(" Wrong Command Format ( logdir /path/to/logdir/ )\n");
return;
}
-
+ if ( nlsr->logDir)
+ free(nlsr->logDir);
nlsr->logDir=(char *)calloc(strlen(dir)+1,sizeof(char));
memcpy(nlsr->logDir,dir,strlen(dir)+1);
}
@@ -558,7 +559,8 @@
free(nlsr->topo_prefix);
if ( topo_prefix[strlen(topo_prefix)-1] == '/' )
topo_prefix[strlen(topo_prefix)-1]='\0';
-
+ if(nlsr->topo_prefix)
+ free(nlsr->topo_prefix);
nlsr->topo_prefix=(char *)calloc(strlen(topo_prefix)+1,sizeof(char));
memcpy(nlsr->topo_prefix,topo_prefix,strlen(topo_prefix)+1);
printf ("Topo prefix is: %s", nlsr->topo_prefix);;
@@ -590,7 +592,8 @@
free(nlsr->slice_prefix);
if ( slice_prefix[strlen(slice_prefix)-1] == '/' )
slice_prefix[strlen(slice_prefix)-1]='\0';
-
+ if( nlsr->slice_prefix)
+ free(nlsr->slice_prefix);
nlsr->slice_prefix=(char *)calloc(strlen(slice_prefix)+1,sizeof(char));
memcpy(nlsr->slice_prefix,slice_prefix,strlen(slice_prefix)+1);
}
diff --git a/nlsr_lsdb.c b/nlsr_lsdb.c
index e46f60d..d185096 100644
--- a/nlsr_lsdb.c
+++ b/nlsr_lsdb.c
@@ -903,6 +903,8 @@
new_adj_lsa->no_link=adj_lsa->no_link;
+ if(new_adj_lsa->body )
+ free(new_adj_lsa->body);
new_adj_lsa->body=(char *)calloc(strlen(adj_lsa->body)+1,sizeof(char));
//memset(new_adj_lsa->body,0,strlen(adj_lsa->body)+1);
memcpy(new_adj_lsa->body,adj_lsa->body,strlen(adj_lsa->body)+1);
@@ -1461,7 +1463,7 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
- struct alsa *adj_lsa=(struct alsa*)malloc(sizeof(struct alsa ));
+ struct alsa *adj_lsa;//=(struct alsa*)malloc(sizeof(struct alsa ));
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -2034,6 +2036,7 @@
ccn_charbuf_destroy(&lsa_data);
+ free(data);
}
void
@@ -2057,6 +2060,7 @@
write_data_to_repo(data, repo_content_prefix);
ccn_charbuf_destroy(&lsa_data);
+ free(data);
}
@@ -2177,9 +2181,9 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__,"install_cor_lsa called \n");
- char *time_stamp=(char *)malloc(20);
- memset(time_stamp,0,20);
- get_current_timestamp_micro(time_stamp);
+ //char *time_stamp=(char *)malloc(20);
+ //memset(time_stamp,0,20);
+ //get_current_timestamp_micro(time_stamp);
char *key=(char *)malloc(cor_lsa->header->orig_router->length+4);
@@ -2207,13 +2211,14 @@
new_cor_lsa->header->orig_router=(struct name_prefix *)malloc(sizeof(struct name_prefix ));
new_cor_lsa->header->orig_router->name=(char *)malloc(strlen(cor_lsa->header->orig_router->name)+1);
- memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
+ //memset(new_cor_lsa->header->orig_router->name,0,strlen(cor_lsa->header->orig_router->name)+1);
memcpy(new_cor_lsa->header->orig_router->name,cor_lsa->header->orig_router->name,strlen(cor_lsa->header->orig_router->name)+1);
new_cor_lsa->header->orig_router->length=cor_lsa->header->orig_router->length;
- new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free
- memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
- memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
+ //new_cor_lsa->header->orig_time=(char *)malloc(strlen(cor_lsa->header->orig_time)+1); //free
+ //memset(new_cor_lsa->header->orig_time,0,strlen(cor_lsa->header->orig_time)+1);
+ //memcpy(new_cor_lsa->header->orig_time,cor_lsa->header->orig_time,strlen(cor_lsa->header->orig_time)+1);
+ new_cor_lsa->header->orig_time=get_current_timestamp_micro_v2();
new_cor_lsa->header->ls_type=cor_lsa->header->ls_type;
@@ -2314,7 +2319,7 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"get_adj_lsa_data called \n");
- struct clsa *cor_lsa=(struct clsa*)malloc(sizeof(struct clsa ));
+ struct clsa *cor_lsa;//=(struct clsa*)malloc(sizeof(struct clsa ));
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -2414,6 +2419,7 @@
free(lst);
free(key);
free(repo_key);
+ free(data);
ccn_charbuf_destroy(&lsa_data);
}
diff --git a/nlsr_ndn.c b/nlsr_ndn.c
index db9c469..c605ad0 100644
--- a/nlsr_ndn.c
+++ b/nlsr_ndn.c
@@ -106,7 +106,7 @@
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Neighbor: %s Length: %d\n",
nbr->name,nbr->length);
-
+ free(neighbor);
}
/**
@@ -150,8 +150,8 @@
}
len++;
- char *neighbor=(char *)malloc(len);
- memset(neighbor,0,len);
+ char *neighbor=(char *)calloc(len,sizeof(char));
+ //memset(neighbor,0,len);
for(i=nlsr_position+3+offset; i<info->interest_comps->n-1;i++)
{
@@ -173,6 +173,7 @@
writeLogg(__FILE__,__FUNCTION__,__LINE__,"LSA Identifier: %s Length: "
"%d\n",lsaId->name,lsaId->length-1);
+ free(neighbor);
}
diff --git a/nlsr_npt.c b/nlsr_npt.c
index 8a04ff0..48577cb 100644
--- a/nlsr_npt.c
+++ b/nlsr_npt.c
@@ -51,7 +51,7 @@
ne->orig_router=(char *)malloc(strlen(orig_router)+1);
memset(ne->orig_router,0,strlen(orig_router)+1);
- memcpy(ne->orig_router,orig_router,strlen(orig_router));
+ memcpy(ne->orig_router,orig_router,strlen(orig_router)+1);
@@ -633,7 +633,7 @@
printf("Face Not Found \n");
if ( nlsr->detailed_logging )
writeLogg(__FILE__,__FUNCTION__,__LINE__,"Face Not Found \n");
- struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
+ struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
fle=ef->data;
fle->next_hop_face=face_id;
fle->route_cost=route_cost;
diff --git a/nlsr_route.c b/nlsr_route.c
index b6619ef..2a25747 100644
--- a/nlsr_route.c
+++ b/nlsr_route.c
@@ -519,7 +519,7 @@
add_map_entry(char *router)
{
- struct map_entry *me=(struct map_entry*)malloc(sizeof(struct map_entry ));
+ struct map_entry *me;//=(struct map_entry*)malloc(sizeof(struct map_entry ));
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -632,7 +632,7 @@
add_rev_map_entry(long int mapping_number, char *router)
{
- struct map_entry *me=(struct map_entry*)malloc(sizeof(struct map_entry ));
+ struct map_entry *me;//=(struct map_entry*)malloc(sizeof(struct map_entry ));
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -944,7 +944,7 @@
return ;
}
- struct routing_table_entry *rte=(struct routing_table_entry *)malloc(sizeof(struct routing_table_entry));
+ struct routing_table_entry *rte;//=(struct routing_table_entry *)malloc(sizeof(struct routing_table_entry));
struct hashtb_enumerator ee;
struct hashtb_enumerator *e = ⅇ
@@ -1048,7 +1048,7 @@
res1 = hashtb_seek(ef, &next_hop_face, sizeof(next_hop_face), 0);
if( res1 == HT_NEW_ENTRY)
{
- struct face_list_entry *fle=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
+ struct face_list_entry *fle;//=(struct face_list_entry *)malloc(sizeof(struct face_list_entry));
fle=ef->data;
fle->next_hop_face=next_hop_face;
fle->route_cost=route_cost;
diff --git a/nlsr_sync.c b/nlsr_sync.c
index fbc679b..199b1df 100644
--- a/nlsr_sync.c
+++ b/nlsr_sync.c
@@ -591,7 +591,7 @@
struct ccn_charbuf *topo = ccn_charbuf_create();
nlsr->closure=(struct ccns_name_closure *)
- calloc(1,sizeof(struct ccns_name_closure));
+ calloc(1,sizeof(struct ccns_name_closure)); // leak
nlsr->slice = ccns_slice_create();