diff options
author | Eric Wong <normalperson@yhbt.net> | 2006-08-14 13:46:51 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2006-08-14 13:46:51 +0000 |
commit | 6459b3ee29e13d5141b9e7b40bb4abce68c404be (patch) | |
tree | 647c70e2896da491a1b96db0dd7f7c9ddb87b4d2 /src/path.c | |
parent | 4fe965c3044888bafa6c86e40724c20faa16f972 (diff) | |
download | mpd-6459b3ee29e13d5141b9e7b40bb4abce68c404be.tar.gz mpd-6459b3ee29e13d5141b9e7b40bb4abce68c404be.tar.xz mpd-6459b3ee29e13d5141b9e7b40bb4abce68c404be.zip |
Revert leaks from r4311, and also the leak fixes as a result of that
utf8ToFsCharset() and fsCharsetToUtf8() got very broken in r4311, and
resulted in several commits to fix those leaks. Unfortunately, not all
of those newly introduced leaks were fixed, nor was the result pretty.
Also, fixed a double-free in lsPlaylists(). This is very hard
to trigger (and therefore exploit) at the moment because we
check printDirectoryInfo() beforehand.
Intended behavior for utf8ToFsCharset() and fsCharsetToUtf8() as
God^H^H^Hshank originally intended is now documented in path.h
to prevent future errors like this.
mpd could still use some good valgrind testing before the 0.12.0
release.
<plug>In addition to reducing heap fragmentation, malloc
reductions from mpd-ke greatly reduces the chance of leaks from
happening due to programming errors.</plug>
git-svn-id: https://svn.musicpd.org/mpd/trunk@4639 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/path.c')
-rw-r--r-- | src/path.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/path.c b/src/path.c index 69c86391b..b05843514 100644 --- a/src/path.c +++ b/src/path.c @@ -41,18 +41,18 @@ const char *musicDir; static const char *playlistDir; static char *fsCharset = NULL; -static char *pathConvCharset(char *to, char *from, char *str) +static char *pathConvCharset(char *to, char *from, char *str, char *ret) { - if (setCharSetConversion(to, from) == 0) { - return convStrDup(str); - } - - return NULL; + if (ret) + free(ret); + return setCharSetConversion(to, from) ? NULL : convStrDup(str); } char *fsCharsetToUtf8(char *str) { - char *ret = pathConvCharset("UTF-8", fsCharset, str); + static char *ret = NULL; + + ret = pathConvCharset("UTF-8", fsCharset, str, ret); if (ret && !validUtf8String(ret)) { free(ret); @@ -64,7 +64,9 @@ char *fsCharsetToUtf8(char *str) char *utf8ToFsCharset(char *str) { - char *ret = pathConvCharset(fsCharset, "UTF-8", str); + static char *ret = NULL; + + ret = pathConvCharset(fsCharset, "UTF-8", str, ret); if (!ret) ret = strdup(str); |