Menu

#109 globecomice dumps core

open
nobody
None
5
2005-08-27
2005-08-27
snotblower
No

globecomice will dump core after running for some
amount of time. It appears this problem is due to a
malloc() with no corresponding free() and no check to
see that the malloc() succeeds.

<snippet>
chopped_filename =
(char*)malloc(strlen(filename)*sizeof(char));
strcpy(chopped_filename, filename);
chopped_filename[strlen(chopped_filename)-4] = '\0';
chopped_filename =
chopped_filename+(strlen(chopped_filename)-1);
while ((*chopped_filename != '/') &&
(*chopped_filename != '\0'))
chopped_filename--;
chopped_filename++;

shout_update_metadata(conn, chopped_filename);
</snippet>

Personally I dont even see the need for the malloc.
filename is a known size, so strncpy'ing it to a fixed
size buffer would work.

Also, I actually just commented all this out and
replaced chopped_filename with filename in the
shout_update_metadata, which gives the full filename
and actually contains useful info in my case (artist
name and album name).

Also if this is going to be corrected with the chopped
filename, I might suggest using basename() instead of
re-implementing the wheel.

Discussion


Log in to post a comment.

Auth0 Logo