Hello.
I have such a code:
Code:
FILE *plik;
        if(argc > 1)
                plik = fopen(argv[1], "r");
        if(argc <= 1 || plik == NULL)
        {
                plik = stdin;
        }
and now, can i just do fclose(plik) or i have to check if plik == stdin, and if not, then fclose(plik). Would it be something wrong to do fclose(plik) when plik=stdin ?

And i have also a question about mem leak in my program. I used valgrind to investigate it:
==13011==
==13011== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==13011== malloc/free: in use at exit: 4096 bytes in 1 blocks.
==13011== malloc/free: 806 allocs, 805 frees, 35664 bytes allocated.
==13011== For counts of detected errors, rerun with: -v
==13011== searching for pointers to 1 not-freed blocks.
==13011== checked 1353972 bytes.
==13011==
==13011== 4096 bytes in 1 blocks are still reachable in loss record 1 of 1
==13011== at 0x3C034183: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck.so)
==13011== by 0x3C108DAD: __smakebuf (in /lib/libc.so.5)
==13011== by 0x3C108D1D: __swsetup (in /lib/libc.so.5)
==13011== by 0x3C0FE606: __vfprintf (in /lib/libc.so.5)
==13011==
==13011== LEAK SUMMARY:
==13011== definitely lost: 0 bytes in 0 blocks.
==13011== possibly lost: 0 bytes in 0 blocks.
==13011== still reachable: 4096 bytes in 1 blocks.
==13011== suppressed: 0 bytes in 0 blocks.
So it seems there isn't a pointer losing but still, there is one more alloc than free. I suspect that this one more alloc is made by program, because my main() declaration looks like:
Code:
int main(int argc, char *argv[])
but do I have to free it somewhere or am i wrong ?
Regards,
apacz.