Commit 1b692d8a authored by Akira TAGOH's avatar Akira TAGOH

Fix the wrong estimation for the memory usage information in fontconfig

parent 5254a663
...@@ -231,7 +231,7 @@ cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBoo ...@@ -231,7 +231,7 @@ cache_print_set (FcFontSet *set, FcStrSet *dirs, const FcChar8 *base_name, FcBoo
if (s) if (s)
{ {
printf ("%s", s); printf ("%s", s);
free (s); FcStrFree (s);
} }
} }
if (verbose && !set->nfont && !ndir) if (verbose && !set->nfont && !ndir)
......
...@@ -183,7 +183,7 @@ main (int argc, char **argv) ...@@ -183,7 +183,7 @@ main (int argc, char **argv)
if (s) if (s)
{ {
printf ("%s", s); printf ("%s", s);
free (s); FcStrFree (s);
} }
} }
} }
......
...@@ -230,7 +230,7 @@ main (int argc, char **argv) ...@@ -230,7 +230,7 @@ main (int argc, char **argv)
if (s) if (s)
{ {
printf ("%s", s); printf ("%s", s);
free (s); FcStrFree (s);
} }
} }
......
...@@ -176,7 +176,7 @@ main (int argc, char **argv) ...@@ -176,7 +176,7 @@ main (int argc, char **argv)
if (s) if (s)
{ {
printf ("%s", s); printf ("%s", s);
free (s); FcStrFree (s);
} }
} }
else else
......
...@@ -165,7 +165,7 @@ main (int argc, char **argv) ...@@ -165,7 +165,7 @@ main (int argc, char **argv)
if (s) if (s)
{ {
printf ("%s", s); printf ("%s", s);
free (s); FcStrFree (s);
} }
} }
else else
......
...@@ -168,7 +168,7 @@ main (int argc, char **argv) ...@@ -168,7 +168,7 @@ main (int argc, char **argv)
if (s) if (s)
{ {
printf ("%s", s); printf ("%s", s);
free (s); FcStrFree (s);
} }
} }
else else
......
...@@ -1698,17 +1698,17 @@ static FcChar8 * ...@@ -1698,17 +1698,17 @@ static FcChar8 *
FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file) FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
{ {
FcChar8 *path; FcChar8 *path;
int size; int size, osize;
if (!dir) if (!dir)
dir = (FcChar8 *) ""; dir = (FcChar8 *) "";
size = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1; osize = strlen ((char *) dir) + 1 + strlen ((char *) file) + 1;
/* /*
* workaround valgrind warning because glibc takes advantage of how it knows memory is * workaround valgrind warning because glibc takes advantage of how it knows memory is
* allocated to implement strlen by reading in groups of 4 * allocated to implement strlen by reading in groups of 4
*/ */
size = (size + 3) & ~3; size = (osize + 3) & ~3;
path = malloc (size); path = malloc (size);
if (!path) if (!path)
...@@ -1729,11 +1729,12 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file) ...@@ -1729,11 +1729,12 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
#endif #endif
strcat ((char *) path, (char *) file); strcat ((char *) path, (char *) file);
FcMemAlloc (FC_MEM_STRING, size); FcMemAlloc (FC_MEM_STRING, osize);
if (access ((char *) path, R_OK) == 0) if (access ((char *) path, R_OK) == 0)
return path; return path;
FcStrFree (path); FcStrFree (path);
return 0; return 0;
} }
...@@ -1853,6 +1854,7 @@ FcConfigXdgCacheHome (void) ...@@ -1853,6 +1854,7 @@ FcConfigXdgCacheHome (void)
ret = malloc (len + 7 + 1); ret = malloc (len + 7 + 1);
if (ret) if (ret)
{ {
FcMemAlloc (FC_MEM_STRING, len + 7 + 1);
memcpy (ret, home, len); memcpy (ret, home, len);
memcpy (&ret[len], FC_DIR_SEPARATOR_S ".cache", 7); memcpy (&ret[len], FC_DIR_SEPARATOR_S ".cache", 7);
ret[len + 7] = 0; ret[len + 7] = 0;
...@@ -1878,6 +1880,7 @@ FcConfigXdgConfigHome (void) ...@@ -1878,6 +1880,7 @@ FcConfigXdgConfigHome (void)
ret = malloc (len + 8 + 1); ret = malloc (len + 8 + 1);
if (ret) if (ret)
{ {
FcMemAlloc (FC_MEM_STRING, len + 8 + 1);
memcpy (ret, home, len); memcpy (ret, home, len);
memcpy (&ret[len], FC_DIR_SEPARATOR_S ".config", 8); memcpy (&ret[len], FC_DIR_SEPARATOR_S ".config", 8);
ret[len + 8] = 0; ret[len + 8] = 0;
...@@ -1903,6 +1906,7 @@ FcConfigXdgDataHome (void) ...@@ -1903,6 +1906,7 @@ FcConfigXdgDataHome (void)
ret = malloc (len + 13 + 1); ret = malloc (len + 13 + 1);
if (ret) if (ret)
{ {
FcMemAlloc (FC_MEM_STRING, len + 13 + 1);
memcpy (ret, home, len); memcpy (ret, home, len);
memcpy (&ret[len], FC_DIR_SEPARATOR_S ".local" FC_DIR_SEPARATOR_S "share", 13); memcpy (&ret[len], FC_DIR_SEPARATOR_S ".local" FC_DIR_SEPARATOR_S "share", 13);
ret[len + 13] = 0; ret[len + 13] = 0;
......
...@@ -294,7 +294,7 @@ interpret_builtin (FcFormatContext *c, ...@@ -294,7 +294,7 @@ interpret_builtin (FcFormatContext *c,
if (new_str) if (new_str)
{ {
FcStrBufString (buf, new_str); FcStrBufString (buf, new_str);
free (new_str); FcStrFree (new_str);
return FcTrue; return FcTrue;
} }
else else
...@@ -1014,7 +1014,7 @@ interpret_convert (FcFormatContext *c, ...@@ -1014,7 +1014,7 @@ interpret_convert (FcFormatContext *c,
if (new_str) if (new_str)
{ {
FcStrBufString (buf, new_str); FcStrBufString (buf, new_str);
free (new_str); FcStrFree (new_str);
return FcTrue; return FcTrue;
} }
else else
......
...@@ -1046,7 +1046,8 @@ FcSharedStrFree (const FcChar8 *name) ...@@ -1046,7 +1046,8 @@ FcSharedStrFree (const FcChar8 *name)
{ {
*p = b->next; *p = b->next;
size = sizeof (struct objectBucket) + strlen ((char *)name) + 1; size = sizeof (struct objectBucket) + strlen ((char *)name) + 1;
FcMemFree (FC_MEM_SHAREDSTR, size + sizeof (int)); size = (size + 3) & ~3;
FcMemFree (FC_MEM_SHAREDSTR, size);
free (b); free (b);
} }
return FcTrue; return FcTrue;
......
...@@ -833,6 +833,7 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c) ...@@ -833,6 +833,7 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c)
if (buf->allocated) if (buf->allocated)
{ {
size = buf->size * 2; size = buf->size * 2;
FcMemFree (FC_MEM_STRBUF, buf->size);
new = realloc (buf->buf, size); new = realloc (buf->buf, size);
} }
else else
...@@ -850,8 +851,6 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c) ...@@ -850,8 +851,6 @@ FcStrBufChar (FcStrBuf *buf, FcChar8 c)
buf->failed = FcTrue; buf->failed = FcTrue;
return FcFalse; return FcFalse;
} }
if (buf->size)
FcMemFree (FC_MEM_STRBUF, buf->size);
FcMemAlloc (FC_MEM_STRBUF, size); FcMemAlloc (FC_MEM_STRBUF, size);
buf->size = size; buf->size = size;
buf->buf = new; buf->buf = new;
......
...@@ -1359,6 +1359,7 @@ FcParseRange (FcConfigParse *parse) ...@@ -1359,6 +1359,7 @@ FcParseRange (FcConfigParse *parse)
break; break;
default: default:
FcConfigMessage (parse, FcSevereError, "invalid element in range"); FcConfigMessage (parse, FcSevereError, "invalid element in range");
n = 0;
break; break;
} }
if (count == 1) if (count == 1)
...@@ -1864,12 +1865,14 @@ FcParseDir (FcConfigParse *parse) ...@@ -1864,12 +1865,14 @@ FcParseDir (FcConfigParse *parse)
size_t plen = strlen ((const char *)prefix); size_t plen = strlen ((const char *)prefix);
size_t dlen = strlen ((const char *)data); size_t dlen = strlen ((const char *)data);
FcMemFree (FC_MEM_STRING, plen + 1);
prefix = realloc (prefix, plen + 1 + dlen + 1); prefix = realloc (prefix, plen + 1 + dlen + 1);
if (!prefix) if (!prefix)
{ {
FcConfigMessage (parse, FcSevereError, "out of memory"); FcConfigMessage (parse, FcSevereError, "out of memory");
goto bail; goto bail;
} }
FcMemAlloc (FC_MEM_STRING, plen + 1 + dlen + 1);
prefix[plen] = FC_DIR_SEPARATOR; prefix[plen] = FC_DIR_SEPARATOR;
memcpy (&prefix[plen + 1], data, dlen); memcpy (&prefix[plen + 1], data, dlen);
prefix[plen + 1 + dlen] = 0; prefix[plen + 1 + dlen] = 0;
...@@ -1934,7 +1937,7 @@ FcParseDir (FcConfigParse *parse) ...@@ -1934,7 +1937,7 @@ FcParseDir (FcConfigParse *parse)
bail: bail:
if (prefix) if (prefix)
free (prefix); FcStrFree (prefix);
} }
static void static void
...@@ -1957,12 +1960,14 @@ FcParseCacheDir (FcConfigParse *parse) ...@@ -1957,12 +1960,14 @@ FcParseCacheDir (FcConfigParse *parse)
size_t plen = strlen ((const char *)prefix); size_t plen = strlen ((const char *)prefix);
size_t dlen = strlen ((const char *)data); size_t dlen = strlen ((const char *)data);
FcMemFree (FC_MEM_STRING, plen + 1);
prefix = realloc (prefix, plen + 1 + dlen + 1); prefix = realloc (prefix, plen + 1 + dlen + 1);
if (!prefix) if (!prefix)
{ {
FcConfigMessage (parse, FcSevereError, "out of memory"); FcConfigMessage (parse, FcSevereError, "out of memory");
goto bail; goto bail;
} }
FcMemAlloc (FC_MEM_STRING, plen + 1 + dlen + 1);
prefix[plen] = FC_DIR_SEPARATOR; prefix[plen] = FC_DIR_SEPARATOR;
memcpy (&prefix[plen + 1], data, dlen); memcpy (&prefix[plen + 1], data, dlen);
prefix[plen + 1 + dlen] = 0; prefix[plen + 1 + dlen] = 0;
...@@ -2053,12 +2058,14 @@ FcParseInclude (FcConfigParse *parse) ...@@ -2053,12 +2058,14 @@ FcParseInclude (FcConfigParse *parse)
size_t plen = strlen ((const char *)prefix); size_t plen = strlen ((const char *)prefix);
size_t dlen = strlen ((const char *)s); size_t dlen = strlen ((const char *)s);
FcMemFree (FC_MEM_STRING, plen + 1);
prefix = realloc (prefix, plen + 1 + dlen + 1); prefix = realloc (prefix, plen + 1 + dlen + 1);
if (!prefix) if (!prefix)
{ {
FcConfigMessage (parse, FcSevereError, "out of memory"); FcConfigMessage (parse, FcSevereError, "out of memory");
goto bail; goto bail;
} }
FcMemAlloc (FC_MEM_STRING, plen + 1 + dlen + 1);
prefix[plen] = FC_DIR_SEPARATOR; prefix[plen] = FC_DIR_SEPARATOR;
memcpy (&prefix[plen + 1], s, dlen); memcpy (&prefix[plen + 1], s, dlen);
prefix[plen + 1 + dlen] = 0; prefix[plen + 1 + dlen] = 0;
...@@ -2076,7 +2083,7 @@ FcParseInclude (FcConfigParse *parse) ...@@ -2076,7 +2083,7 @@ FcParseInclude (FcConfigParse *parse)
bail: bail:
if (prefix) if (prefix)
free (prefix); FcStrFree (prefix);
} }
typedef struct _FcOpMap { typedef struct _FcOpMap {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment