3
I am making a data structure program and am getting the following error:
Arq(1966,0x7fff7970f300) malloc: * error for Object 0x7fc058404c38: incorrect checksum for Freed Object - Object was probably modified after being Freed. * set a breakpoint in malloc_error_break to debug
But I’m not doing any free. The situation is this: I am working with an AVL tree, the first time I try to insert an element in the tree, it works smoothly.
Now, if I try to insert another element, either in the same tree or another tree, the same record or the same, points out this error, always at these addresses, I searched several things but did not find the error.
I would like to know where the error is, because I can’t imagine what to look for in the functions, since the first time it works normally but the second time it points out that error.
Part of the code:
NODO *D;
REG * R;
int ok;
inicializar(&D);
R = criar_registro("GUT-2020","MCBA123","Carro","Azul",3,"Jose Joaquim", "1234","3214543");
inserir(&D, "GUT-2020", *R, &ok);
printf("Impressao: \n\n");
exibir(D);
//ate aqui tudo certo
REG * R2;
NODO * D2;
int ok2;
inicializar(&D2);
R2 = criar_registro("GUT-2021","MCBA123","Carro","Azul",3,"Jose Joaquim", "1234","3214543");
inserir(&D2, "GUT-2021", *R2, &ok2); //erro
functions involved in the problem:
void inicializar(NODO **Dic)
{
*Dic = NULL;
}
REG * criar_registro(char placa[], char chassi[], char marca[], char modelo[], char portas, char proprietario[], char cpf[], char telefone[])
{
REG * registro = (REG*)malloc(sizeof(REG));
strcpy(registro->chave,placa);
strcpy(registro->carro.placa,placa);
strcpy(registro->carro.chassi,chassi);
strcpy(registro->carro.marca,marca);
strcpy(registro->carro.modelo,modelo);
registro->carro.portas = portas;
strcpy(registro->carro.proprietario,proprietario);
strcpy(registro->carro.cpf,cpf);
strcpy(registro->carro.telefone,telefone);
return registro;
}
and the part that is executed in function insert is as follows: The error happens the second time I run it, for a variable pointing to NULL (same as the first time I run it, but this first time works correctly)
NODO * A
if (*Dic == NULL)
{ //{INSERÇÃO}
A = (NODO*) malloc(sizeof(Dic));
if (A == NULL)
return 0;
A->esq = NULL;
A->dir = NULL;
strcpy(A->reg.chave, chave);
A->reg.carro = reg.carro;
A->FB = 0;
*OK = 1;
*Dic = A;
return 1;
}
The problem may be in the functions. Post their code, if possible.
– mutlei
posted the code of the functions that are executed!
– Guilherme Oliveira