C-Stack Smashing Detected - how to properly initialize a graph by adjacency list and insert edges?

I am receiving, sporadically and without having made any changes to the code or input, an error called Stack Smashing Detected.

The only things I'm doing is initializing a graph and inserting an edge into it, follow the code below:

typedef int TipoPeso;

typedef struct taresta {  
    int vdest;  
    TipoPeso peso;  
    struct taresta * prox;  
}TipoAresta;  

typedef TipoAresta* TipoApontador;  

typedef struct {   
   TipoApontador *listaAdj;  
   int numVertices;  
   int numArestas;  
} TipoGrafo;  

bool verificaValidadeVertice(int v, TipoGrafo *grafo){  
   if(v > grafo->numVertices) return false;  
   if(v < 1) return false;  

   return true;  
}

bool inicializaGrafo(TipoGrafo* grafo, int nv){  
   //verifica se nv é válido  
   if(nv<1) return false;  


   //reserva memória para o grafo  
   grafo = (TipoGrafo*) malloc(sizeof(TipoGrafo));  
   grafo->numVertices = nv;  
   grafo->numArestas = 0;  


   //reserva memoria para a ListAdj*  
   grafo->listaAdj = (TipoApontador*) malloc(sizeof(TipoApontador)*(nv + 1));  

   //inicializa a lista com AN  
   for(int i = 0; i<= nv; i++){  
      grafo->listaAdj[i] = NULL;  
   }  
   return true;  
 }

void insereAresta(int v1, int v2, TipoPeso peso, TipoGrafo *grafo){
   if(verificaValidadeVertice(v1, grafo) && verificaValidadeVertice(v2, grafo)){
    TipoApontador novo = (TipoApontador) malloc(sizeof(TipoAresta));
    novo->peso = peso;
    novo->prox = grafo->listaAdj[v1];
    novo->vdest = v2;
    grafo->listaAdj[v1] = novo;
    grafo->numArestas = grafo->numArestas +1;
    //printf("peso de listaAdj[v1] %d ", grafo->listaAdj[v1]->peso);
   }
}

int main()
{
  TipoGrafo* g1;
  inicializaGrafo(g1, 5);
  //insere arestas

  TipoPeso i = 1;
  insereAresta(1, 2, i, &g1);
  //printf("aqui %d ", g1->listaAdj[1]->peso);
  //insereAresta(1, 3, 4, &g1);
  //insereAresta(2, 4, 7, &g1);
  //insereAresta(2, 3, 2, &g1);
  /*insereAresta(3, 4, 2, &g1);
  insereAresta(3, 5, 1, &g1);
  insereAresta(4, 5, 1, &g1);
  */

  printf("Compilou carajo!\n");
  return 0;
}
Author: Daniel Mendes, 2018-05-08