Why does Valgrind think that this memory is "definitely lost"?
<p>Valgrind reports that Texture *tex is definitely lost. But I save this pointer in mtl->tex to free it later. Here is detailed message from valgrind:</p>

<blockquote>
  <p>==17191== 4 bytes in 1 blocks are definitely lost in loss record 1 of 1
  ==17191==    at 0x4C2ABD0: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  ==17191==    by 0x4005FA: assignTex (test.c:30)
  ==17191==    by 0x400689: main (test.c:47)</p>
</blockquote>

<p>Here is the code(MCVE):</p>

<pre><code>#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

typedef struct Tex {
    int a;
} Tex;

typedef struct MTL {
    char *textureFilename;
    struct Tex *tex;
} MTL;

void freeMtl(MTL *mtl) {
    if(!mtl) return;

    if(mtl-&gt;tex) free(mtl-&gt;tex);
    free(mtl);
}

void doStuff(Tex *tex) {
    tex-&gt;a = 5;
}

char err_is_error_set() {
    return 0;
}

void assignTex(MTL *mtl) {
    if(strlen(mtl-&gt;textureFilename) != 0) {
        Tex *tex = (Tex*)malloc(sizeof(Tex));
        memset(tex, 0, sizeof(Tex));

        doStuff(tex);
        if(err_is_error_set()) {
            return;
        }

        mtl-&gt;tex = tex;
    }
}

int main(int argc, char **argv) {
    MTL *mtl = (MTL*)malloc(sizeof(MTL));
    memset(mtl, 0, sizeof(MTL));
    mtl-&gt;textureFilename = "Test";

    assignTex(mtl);
    assignTex(mtl);

    freeMtl(mtl);

    return 0;
}
</code></pre>

<p>Why is it definitely lost?</p>