Я работаю над программой Hash Table C. И у меня есть только одна утечка памяти в следующей функции:Невозможно освободить память в C
void put(char *key, char *value, TD* H)
{
if(!get(key, H))
{
int poz = fd(key, H->M);
CelulaH *aux, *aux2;
aux = malloc(sizeof(CelulaH));
aux->key = malloc(50);
aux->value = malloc(50);
strcpy(aux->key, key);
strcpy(aux->value, value);
if(H->v[poz] == NULL)
{
H->v[poz] = (TCelulaG*)malloc(sizeof(TCelulaG));
H->v[poz]->info = malloc(sizeof(CelulaH));
memcpy(H->v[poz]->info, aux, sizeof(CelulaH));
H->v[poz]->urm = NULL;
}
else
InsLGO(&H->v[poz], aux, sizeof(CelulaH), cmp);
//if(aux)
free(aux);
}
}
У меня есть три структуры: TD, CelulaH, TCelulaG. Вот как они выглядят:
typedef struct celula
{
struct celula* urm;
void* info;
} TCelulaG, *TLG, **ALG;
typedef struct
{
size_t M;
TFhash fd;
TLG *v;
} TD;
typedef struct
{
char *key, *value;
} CelulaH;
И это выход Valgrind:
==5380== Conditional jump or move depends on uninitialised value(s)
==5380== at 0x8048A2B: get (in /home/luzi/TemaSD/tema1)
==5380== by 0x8048B26: put (in /home/luzi/TemaSD/tema1)
==5380== by 0x8048E19: CitireComenzi (in /home/luzi/TemaSD/tema1)
==5380== by 0x804909E: main (in /home/luzi/TemaSD/tema1)
==5380==
==5380== Conditional jump or move depends on uninitialised value(s)
==5380== at 0x8048BB7: put (in /home/luzi/TemaSD/tema1)
==5380== by 0x8048E19: CitireComenzi (in /home/luzi/TemaSD/tema1)
==5380== by 0x804909E: main (in /home/luzi/TemaSD/tema1)
==5380==
==5380== 50 bytes in 1 blocks are definitely lost in loss record 1 of 2
==5380== at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5380== by 0x8048B60: put (in /home/luzi/TemaSD/tema1)
==5380== by 0x8048E19: CitireComenzi (in /home/luzi/TemaSD/tema1)
==5380== by 0x804909E: main (in /home/luzi/TemaSD/tema1)
==5380==
==5380== 50 bytes in 1 blocks are definitely lost in loss record 2 of 2
==5380== at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==5380== by 0x8048B73: put (in /home/luzi/TemaSD/tema1)
==5380== by 0x8048E19: CitireComenzi (in /home/luzi/TemaSD/tema1)
==5380== by 0x804909E: main (in /home/luzi/TemaSD/tema1)
==5380==
Так единственная проблема, кажется, что сейчас два mallocs в функции «положить». Все остальные маллоки из программы бесплатны, так что это единственные, кто остался свободен. Есть идеи?
«У меня есть только одна утечка памяти» ... что вы знаете о! –