Re: fontconfig: Branch 'master'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I was planning on removing the memory accounting stuff completely.  I mean,
that's what tools like malloc-stats should deal with, not libraries themselves...

b

On 12-12-07 05:10 AM, Akira TAGOH wrote:
>  src/fccfg.c  |    2 ++
>  src/fcinit.c |   16 ++++++++++------
>  src/fclang.c |   26 ++++++++++++++++++++++++--
>  src/fcstr.c  |    5 ++---
>  src/fcxml.c  |   28 ++++++++++++++++------------
>  5 files changed, 54 insertions(+), 23 deletions(-)
> 
> New commits:
> commit e7954674eb4f16d0fed3018cbefb4907c89d2465
> Author: Akira TAGOH <akira@xxxxxxxxx>
> Date:   Fri Dec 7 19:09:36 2012 +0900
> 
>     Fix the wrong estimation for the memory usage information in fontconfig
> 
> diff --git a/src/fccfg.c b/src/fccfg.c
> index d3752e5..45b4869 100644
> --- a/src/fccfg.c
> +++ b/src/fccfg.c
> @@ -1743,6 +1743,8 @@ FcConfigFileExists (const FcChar8 *dir, const FcChar8 *file)
>  #else
>      if ((!path[0] || path[strlen((char *) path)-1] != '/') && file[0] != '/')
>  	strcat ((char *) path, "/");
> +    else
> +	osize--;
>  #endif
>      strcat ((char *) path, (char *) file);
>  
> diff --git a/src/fcinit.c b/src/fcinit.c
> index ab64012..aaf8637 100644
> --- a/src/fcinit.c
> +++ b/src/fcinit.c
> @@ -72,7 +72,7 @@ FcInitLoadConfig (void)
>  
>      if (config->cacheDirs && config->cacheDirs->num == 0)
>      {
> -	FcChar8 *prefix;
> +	FcChar8 *prefix, *p;
>  	size_t plen;
>  
>  	fprintf (stderr,
> @@ -81,12 +81,15 @@ FcInitLoadConfig (void)
>  		 "Fontconfig warning: adding <cachedir>%s</cachedir>\n",
>  		 FC_CACHEDIR);
>  	prefix = FcConfigXdgCacheHome ();
> -	plen = prefix ? strlen ((const char *)prefix) : 0;
>  	if (!prefix)
>  	    goto bail;
> -	prefix = realloc (prefix, plen + 12);
> -	if (!prefix)
> +	plen = prefix ? strlen ((const char *)prefix) : 0;
> +	p = realloc (prefix, plen + 12);
> +	if (!p)
>  	    goto bail;
> +	prefix = p;
> +	FcMemFree (FC_MEM_STRING, plen + 1);
> +	FcMemAlloc (FC_MEM_STRING, plen + 12);
>  	memcpy (&prefix[plen], FC_DIR_SEPARATOR_S "fontconfig", 11);
>  	prefix[plen + 11] = 0;
>  	fprintf (stderr,
> @@ -98,11 +101,12 @@ FcInitLoadConfig (void)
>  	  bail:
>  	    fprintf (stderr,
>  		     "Fontconfig error: out of memory");
> -	    free (prefix);
> +	    if (prefix)
> +		FcStrFree (prefix);
>  	    FcConfigDestroy (config);
>  	    return FcInitFallbackConfig ();
>  	}
> -	free (prefix);
> +	FcStrFree (prefix);
>      }
>  
>      return config;
> diff --git a/src/fclang.c b/src/fclang.c
> index b7e70fc..65d22a9 100644
> --- a/src/fclang.c
> +++ b/src/fclang.c
> @@ -182,7 +182,7 @@ FcLangNormalize (const FcChar8 *lang)
>  {
>      FcChar8 *result = NULL, *s, *orig;
>      char *territory, *encoding, *modifier;
> -    size_t llen, tlen = 0, mlen = 0;
> +    size_t llen, tlen = 0, mlen = 0, ssize;
>  
>      if (!lang || !*lang)
>  	return NULL;
> @@ -197,6 +197,10 @@ FcLangNormalize (const FcChar8 *lang)
>      s = FcStrCopy (lang);
>      if (!s)
>  	goto bail;
> +    /* store the original length of 's' here to let FcMemFree know
> +     * the correct size since we breaks 's' from now on.
> +     */
> +    ssize = strlen ((const char *)s) + 1;
>  
>      /* from the comments in glibc:
>       *
> @@ -282,6 +286,11 @@ FcLangNormalize (const FcChar8 *lang)
>  	else
>  	{
>  	    result = s;
> +	    /* we'll miss the opportunity to reduce the correct size
> +	     * of the allocated memory for the string after that.
> +	     */
> +	    FcMemFree (FC_MEM_STRING, ssize);
> +	    FcMemAlloc (FC_MEM_STRING, strlen((const char *)s) + 1);
>  	    s = NULL;
>  	    goto bail1;
>  	}
> @@ -295,6 +304,11 @@ FcLangNormalize (const FcChar8 *lang)
>  	else
>  	{
>  	    result = s;
> +	    /* we'll miss the opportunity to reduce the correct size
> +	     * of the allocated memory for the string after that.
> +	     */
> +	    FcMemFree (FC_MEM_STRING, ssize);
> +	    FcMemAlloc (FC_MEM_STRING, strlen((const char *)s) + 1);
>  	    s = NULL;
>  	    goto bail1;
>  	}
> @@ -312,14 +326,22 @@ FcLangNormalize (const FcChar8 *lang)
>      else
>      {
>  	result = s;
> +	/* we'll miss the opportunity to reduce the correct size
> +	 * of the allocated memory for the string after that.
> +	 */
> +	FcMemFree (FC_MEM_STRING, ssize);
> +	FcMemAlloc (FC_MEM_STRING, strlen((const char *)s) + 1);
>  	s = NULL;
>      }
>    bail1:
>      if (orig)
> -	free (orig);
> +	FcStrFree (orig);
>    bail0:
>      if (s)
> +    {
>  	free (s);
> +	FcMemFree (FC_MEM_STRING, ssize);
> +    }
>    bail:
>      if (FcDebug () & FC_DBG_LANGSET)
>      {
> diff --git a/src/fcstr.c b/src/fcstr.c
> index 037960d..99b59da 100644
> --- a/src/fcstr.c
> +++ b/src/fcstr.c
> @@ -38,7 +38,6 @@ FcStrCopy (const FcChar8 *s)
>  {
>      int     len;
>      FcChar8 *r;
> -
>      if (!s)
>  	return 0;
>      len = strlen ((char *) s) + 1;
> @@ -1204,7 +1203,7 @@ FcStrSetAddLangs (FcStrSet *strs, const char *languages)
>  	    if (normalized_lang)
>  	    {
>  		FcStrSetAdd (strs, normalized_lang);
> -		free (normalized_lang);
> +		FcStrFree (normalized_lang);
>  		ret = FcTrue;
>  	    }
>  	}
> @@ -1216,7 +1215,7 @@ FcStrSetAddLangs (FcStrSet *strs, const char *languages)
>  	if (normalized_lang)
>  	{
>  	    FcStrSetAdd (strs, normalized_lang);
> -	    free (normalized_lang);
> +	    FcStrFree (normalized_lang);
>  	    ret = FcTrue;
>  	}
>      }
> diff --git a/src/fcxml.c b/src/fcxml.c
> index 72e9eaf..3a94af6 100644
> --- a/src/fcxml.c
> +++ b/src/fcxml.c
> @@ -1849,7 +1849,7 @@ static void
>  FcParseDir (FcConfigParse *parse)
>  {
>      const FcChar8 *attr, *data;
> -    FcChar8 *prefix = NULL;
> +    FcChar8 *prefix = NULL, *p;
>  #ifdef _WIN32
>      FcChar8         buffer[1000];
>  #endif
> @@ -1868,13 +1868,14 @@ FcParseDir (FcConfigParse *parse)
>  	size_t plen = strlen ((const char *)prefix);
>  	size_t dlen = strlen ((const char *)data);
>  
> -	FcMemFree (FC_MEM_STRING, plen + 1);
> -	prefix = realloc (prefix, plen + 1 + dlen + 1);
> -	if (!prefix)
> +	p = realloc (prefix, plen + 1 + dlen + 1);
> +	if (!p)
>  	{
>  	    FcConfigMessage (parse, FcSevereError, "out of memory");
>  	    goto bail;
>  	}
> +	prefix = p;
> +	FcMemFree (FC_MEM_STRING, plen + 1);
>  	FcMemAlloc (FC_MEM_STRING, plen + 1 + dlen + 1);
>  	prefix[plen] = FC_DIR_SEPARATOR;
>  	memcpy (&prefix[plen + 1], data, dlen);
> @@ -1947,7 +1948,7 @@ static void
>  FcParseCacheDir (FcConfigParse *parse)
>  {
>      const FcChar8 *attr;
> -    FcChar8 *prefix = NULL, *data;
> +    FcChar8 *prefix = NULL, *p, *data;
>  
>      attr = FcConfigGetAttribute (parse, "prefix");
>      if (attr && FcStrCmp (attr, (const FcChar8 *)"xdg") == 0)
> @@ -1963,13 +1964,15 @@ FcParseCacheDir (FcConfigParse *parse)
>  	size_t plen = strlen ((const char *)prefix);
>  	size_t dlen = strlen ((const char *)data);
>  
> -	FcMemFree (FC_MEM_STRING, plen + 1);
> -	prefix = realloc (prefix, plen + 1 + dlen + 1);
> -	if (!prefix)
> +	p = realloc (prefix, plen + 1 + dlen + 1);
> +	if (!p)
>  	{
>  	    FcConfigMessage (parse, FcSevereError, "out of memory");
> +	    data = prefix;
>  	    goto bail;
>  	}
> +	prefix = p;
> +	FcMemFree (FC_MEM_STRING, plen + 1);
>  	FcMemAlloc (FC_MEM_STRING, plen + 1 + dlen + 1);
>  	prefix[plen] = FC_DIR_SEPARATOR;
>  	memcpy (&prefix[plen + 1], data, dlen);
> @@ -2043,7 +2046,7 @@ FcParseInclude (FcConfigParse *parse)
>      const FcChar8   *attr;
>      FcBool	    ignore_missing = FcFalse;
>      FcBool	    deprecated = FcFalse;
> -    FcChar8	    *prefix = NULL;
> +    FcChar8	    *prefix = NULL, *p;
>  
>      s = FcStrBufDoneStatic (&parse->pstack->str);
>      if (!s)
> @@ -2065,13 +2068,14 @@ FcParseInclude (FcConfigParse *parse)
>  	size_t plen = strlen ((const char *)prefix);
>  	size_t dlen = strlen ((const char *)s);
>  
> -	FcMemFree (FC_MEM_STRING, plen + 1);
> -	prefix = realloc (prefix, plen + 1 + dlen + 1);
> -	if (!prefix)
> +	p = realloc (prefix, plen + 1 + dlen + 1);
> +	if (!p)
>  	{
>  	    FcConfigMessage (parse, FcSevereError, "out of memory");
>  	    goto bail;
>  	}
> +	prefix = p;
> +	FcMemFree (FC_MEM_STRING, plen + 1);
>  	FcMemAlloc (FC_MEM_STRING, plen + 1 + dlen + 1);
>  	prefix[plen] = FC_DIR_SEPARATOR;
>  	memcpy (&prefix[plen + 1], s, dlen);
> _______________________________________________
> Fontconfig mailing list
> Fontconfig@xxxxxxxxxxxxxxxxxxxxx
> http://lists.freedesktop.org/mailman/listinfo/fontconfig
> 

-- 
behdad
http://behdad.org/
_______________________________________________
Fontconfig mailing list
Fontconfig@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/fontconfig


[Index of Archives]     [Fedora Fonts]     [Fedora Users]     [Fedora Cloud]     [Kernel]     [Fedora Packaging]     [Fedora Desktop]     [PAM]     [Gimp Graphics Editor]     [Yosemite News]

  Powered by Linux