Still reachable memory means that it is being pointed to by a global or static pointer. What you want to do is run valgrind with --show-reachable=yes
to see whether it's a problem.
Often times it's harmless and comes from a function like this:
void foo()
{
static char *buffer = 0;
if (buffer == 0)
{
buffer = (char *)malloc(...);
}
}
That malloc will still be reachable. But no matter how many times foo is called, you allocate the buffer exactly once so there is no harm here in not freeing it.
But consider a function like this:
void foo()
{
static node_t *head = 0;
node_t *node = (node_t *)malloc(sizeof(node_t));
if (node)
{
node->next = head;
head = node;
}
...
}
Every time this function is called, another node will be allocated. While you may only leak a few nodes for your test runs, in a production run, you could leak enough that you run out of memory.
One way to tell the difference is to see if different runs always leak the same memory or you leak more memory are test runs with larger inputs.
But again, if you want to be safe, use --show-reachable=yes
and see what's happening.