I have a simple piece of a program thats currently producing some memory leaks according to valgrind and I’m not sure why:
char *filename = strrchr(argv[3], "/") + 1;
file = fopen(fileName, "w");
So as far as I know, I give the program an argv[3] of “test/test2”, and the first line finds the last occurrence of “/”, and then moves one character forward (to “t”). Then the second line opens a file that is a pointer to the char array “test”.
Why is this causing a memory leak?
Well, your code would leak a file handle (the latter fopen is not closed). However, without a more complete example its hard to tell.