ciao a tutti.
ho un problema: ho scritto un programma per determinare minimi percorsi tra i nodi di una rete.
durante l'esecuzione a volte mi segnale errore di violazione di accesso nella funzione calculate_routing in corrispondenza dell'aterisco.
di seguito allego la funzione che mi causa errore, altre funzioni che vengono richiamate da quest'ultima e le strutture utilizzate.
spero che qualcuno possa darmi un consiglio.

codice:
//calculate_routing: Calculate the minimum path for each couple of source-destination nodes
void calculate_routing(NETINFO_PTR netinfo_ptr, LISTNODEPTR adiacence_array, PATH* routing_array, LISTNODEPTR path_array, STATENODE** nodeinfo_mtx) 
{
  int i, j, num, back;
  LISTNODEPTR current = NULL; 
  LISTNODEPTR swapptr;
  LISTNODEPTR cur_adiacence = NULL;
  LISTNODEPTR actual_list;
  enum stop_condition {TRUE, FALSE} stop;
   
  stop = FALSE;

  actual_list = listnode_init();
        
  swapptr = listnode_init();

  //-- Nodes initialization -----------------------
  for (i = 0; i <= netinfo_ptr->size->NNODES - 1; i++) 
  {
    for (j = 0; j <= netinfo_ptr->size->COUPLE_NUM - 1; j++) 
	{   
	  nodeinfo_mtx[i][j].predecessor = INIT_PRED;
	  nodeinfo_mtx[i][j].precedent = INIT_PRED;
	  nodeinfo_mtx[i][j].hop_number = INFINITY;
	  nodeinfo_mtx[i][j].label = tentative;
     }
  }

  //-- Sources initialization ---------------------
  for (i = 0; i <= netinfo_ptr->size->COUPLE_NUM - 1; i++)
  {  
    nodeinfo_mtx[routing_array[i].source][i].label =    permanent;              
    nodeinfo_mtx[routing_array[i].source][i].hop_number = 0;
    routing_array[i].length = 0;
    listnode_insert(actual_list, routing_array[i].source);
    listnode_insert(&path_array[i], routing_array[i].source); 
    
    num = 0;

    while (stop != TRUE) 
	{
      current = actual_list;
      while (current != NULL && stop != TRUE) 
	  {
	    cur_adiacence = &adiacence_array[current->node];
	
	    while (cur_adiacence != NULL && stop != TRUE) 
		{  
*	      if (nodeinfo_mtx[cur_adiacence->node][i].label == tentative)
		  {
	        nodeinfo_mtx[cur_adiacence->node][i].label = permanent;
	        nodeinfo_mtx[cur_adiacence->node][i].hop_number = num;
	        nodeinfo_mtx[cur_adiacence->node][i].predecessor = current->node;
	        listnode_insert(swapptr, cur_adiacence->node);

	        if (cur_adiacence->node == routing_array[i].destination) 
			{
	          stop = TRUE;
	          back = routing_array[i].destination;
	          while (back != routing_array[i].source) 
			  {
		        nodeinfo_mtx[back][i].precedent = nodeinfo_mtx[back][i].predecessor;
		        listnode_insert(&path_array[i], back);
		        back = nodeinfo_mtx[back][i].predecessor;
			  }
	          listnode_insert(&path_array[i],routing_array[i].source);
			}
		  }
	      cur_adiacence = cur_adiacence->listptr;
		}
	    current = current->listptr;
	  }
      listnode_free(actual_list);

      actual_list = listnode_init();
     
      if (stop != TRUE)
	  listnode_copy(swapptr, actual_list); 
		 
      listnode_free(swapptr);
      
      swapptr = listnode_init();
      
      num++;
    }
    routing_array[i].length = num;
    stop = FALSE;
  }
}

codice:
// listnode_init: Initialize a list of nodes
LISTNODEPTR listnode_init() {
  LISTNODEPTR tmp_list = malloc(sizeof(LISTNODE));

  if(tmp_list != NULL) {
    tmp_list->node = -1;
    tmp_list->listptr = NULL;
  }

  return tmp_list;
}

// listnode_insert: Insert a new node in the list of nodes
void listnode_insert(LISTNODEPTR node_list, int node) {
  LISTNODEPTR newnode_ptr, prevnode_ptr, currnode_ptr;
   if (node_list->node == -1)
    node_list->node = node;
  else {
    newnode_ptr = malloc(sizeof(LISTNODE));

    if (newnode_ptr != NULL) {
      newnode_ptr->node = node;
      newnode_ptr->listptr = NULL;
      prevnode_ptr = NULL;
      currnode_ptr = node_list;
      
      while (currnode_ptr != NULL) {
	prevnode_ptr = currnode_ptr;
	currnode_ptr = currnode_ptr->listptr;
      }

      if (prevnode_ptr != NULL)
	prevnode_ptr->listptr = newnode_ptr;
      else
	fprintf(stderr, "\nError: cannot allocate memory for the node.\n");
    }
  }
}

// listnode_free: Clear a list of nodes and free memory
void listnode_free(LISTNODEPTR node_list) {
  LISTNODEPTR aux_ptr, curr_ptr;
  
  if (node_list != NULL) {
    curr_ptr = node_list;
    aux_ptr = curr_ptr->listptr;
    free(curr_ptr);
    curr_ptr = NULL;
    listnode_free(aux_ptr);
  }
}
// listnode_copy: Copy nodes from a list (src) to another (dest)
void listnode_copy(LISTNODEPTR src, LISTNODEPTR dest) {
  while (src != NULL) {
    listnode_insert(dest, src->node);
    src = src->listptr;
  }
}

codice:
// List of nodes
struct listnode {
  int node;
  struct listnode* listptr;
};

typedef struct listnode LISTNODE;
typedef LISTNODE* LISTNODEPTR;

struct nodelinks {
  LISTNODEPTR inlinks;
  LISTNODEPTR outlinks;
};

typedef struct nodelinks NODELINKS;
typedef NODELINKS* NODELINKS_PTR;

// Node State 
struct state {
  int predecessor;
  int precedent;
  int hop_number;
  enum {permanent, tentative} label;
};

typedef struct state STATENODE;

// Routing Path Definition 
struct path {
  int source;
  int destination;
  int length;
  float penalty;
  int rate_quantity;
  int n_path;
}routing;

typedef struct path PATH;

//netinfo: data from files
struct netinfo_const {
  double delta;
  double W;
  double radius;
  double lambda;
  double netdia; 
};

typedef struct netinfo_const NICONST;
typedef NICONST* NICONST_PTR;

struct netinfo_size {
  int NNODES;
  int COUPLE_NUM;
  int POWERLEVELS_NUM;
  int CAPACITYLEVELS_NUM;
};

typedef struct netinfo_size NISIZE;
typedef NISIZE* NISIZE_PTR;

struct netinfo_data {
  double** ncoord_mtx;
  PATH* routing_array;
  double* powercost_array;
  double** pathcouple_mtx;

  double* powerlevel_array;
  double* capacitylevel_array;

  double** normconst_mtx;

  double* sigma_array;
};

typedef struct netinfo_data NIDATA;
typedef NIDATA* NIDATA_PTR;

struct netinfo {
  NICONST_PTR consts;
  NISIZE_PTR size;
  NIDATA_PTR data;
};
typedef struct netinfo NETINFO;
typedef NETINFO* NETINFO_PTR;