I have to implement a function that prints a string and on the screen it does it well, but with the valgrind test the following error comes out and I do not know how to fix it
Invalid read of size 4
at 0x401F91: info_a_texto(rep_info*) (info.cpp:55)
by 0x4032D2: imprimir_cadena(rep_cadena*) (cadena.cpp:490)
by 0x401A3F: main (principal.cpp:289)
Address 0x5cba1a0 is 0 bytes inside a block of size 16 free'd
at 0x4C2F21A: operator delete(void*) (vg_replace_malloc.c:576)
by 0x401EF5: liberar_info(rep_info*&) (info.cpp:40)
by 0x402BA1: liberar_cadena(rep_cadena*&) (cadena.cpp:236)
by 0x401D75: main (principal.cpp:333)
Block was alloc'd at
at 0x4C2E1FC: operator new(unsigned long) (vg_replace_malloc.c:334)
by 0x401E25: crear_info(int, char*) (info.cpp:23)
by 0x4021D0: leer_info(int) (info.cpp:101)
by 0x400B21: leer_cadena() (principal.cpp:56)
by 0x400D68: main (principal.cpp:109)
The point is that I do not understand what is due.
The code of the function is as follows:
void imprimir_cadena(cadena_t cad) {
localizador_t cursor = inicio_cadena(cad);
while (localizador_en_cadena(cursor,cad)) {
printf("(");
printf("%d",numero_info(info_cadena(cursor,cad)));
printf(",");
printf("%s",frase_info(info_cadena(cursor,cad)));
printf(")");
cursor = siguiente(cursor,cad);
}
printf("\n");
}
The chain is composed of a double linked list, with two pagers that indicate its start and end. Each node in the chain contains two pointers "before and after" and a "data", consisting of an int and a string.
I appreciate if someone can give me a hand. Greetings.