Add a check for the case when the parent neighbor may have gone away to avoid using a NULL pointer

This commit is contained in:
Adam Dunkels 2013-11-20 14:08:20 +01:00
parent 0ed7db0f9b
commit 490791eaa4

View File

@ -553,13 +553,17 @@ rpl_add_parent(rpl_dag_t *dag, rpl_dio_t *dio, uip_ipaddr_t *addr)
if(lladdr != NULL) {
/* Add parent in rpl_parents */
p = nbr_table_add_lladdr(rpl_parents, (rimeaddr_t *)lladdr);
p->dag = dag;
p->rank = dio->rank;
p->dtsn = dio->dtsn;
p->link_metric = RPL_INIT_LINK_METRIC * RPL_DAG_MC_ETX_DIVISOR;
if(p == NULL) {
PRINTF("RPL: rpl_add_parent p NULL\n");
} else {
p->dag = dag;
p->rank = dio->rank;
p->dtsn = dio->dtsn;
p->link_metric = RPL_INIT_LINK_METRIC * RPL_DAG_MC_ETX_DIVISOR;
#if RPL_DAG_MC != RPL_DAG_MC_NONE
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
memcpy(&p->mc, &dio->mc, sizeof(p->mc));
#endif /* RPL_DAG_MC != RPL_DAG_MC_NONE */
}
}
return p;