Re: strange code in FcCharSetPutLeaf (spotted by Coverity)

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

 



Le mardi 11 avril 2006 à 10:21 -0400, Patrick Lam a écrit :
> Frederic Crozat wrote:
> > Coverity found two memory leaks in fccharset.c : FcCharSetPutLeaf (#1192
> > and #1193) in the "if (fcs->bank != FC_BANK_DYNAMIC)" TRUE branch :
> > leaves and numbers. But after reading this part of the code, I'm not
> > sure if it is doing anything at all : memory is allocated for leaves and
> > numbers but those variables are not used at all after "if () {} else {}"
> > stuff, so they are leaked and not used at all..
> > 
> > Could somebody with much more knowledge of this code check it ?
> 
> Oops!  I meant to do this:
> 
> Index: src/fccharset.c
> ===================================================================
> RCS file: /cvs/fontconfig/fontconfig/src/fccharset.c,v
> retrieving revision 1.25.4.13
> diff -u -p -r1.25.4.13 fccharset.c
> --- src/fccharset.c     7 Apr 2006 17:27:39 -0000       1.25.4.13
> +++ src/fccharset.c     11 Apr 2006 14:18:55 -0000
> @@ -168,6 +168,7 @@ FcCharSetPutLeaf (FcCharSet *fcs,
>          return FcFalse;
>       if (fcs->bank != FC_BANK_DYNAMIC)
>       {
> +        /* convert to dynamic */
>          int i;
> 
>          leaves = malloc ((fcs->num + 1) * sizeof (FcCharLeaf *));
> @@ -183,6 +184,10 @@ FcCharSetPutLeaf (FcCharSet        *fcs,
>              leaves[i] = FcCharSetGetLeaf(fcs, i);
>          memcpy (numbers, FcCharSetGetNumbers(fcs),
>                  fcs->num * sizeof (FcChar16));
> +
> +       fcs->bank = FC_BANK_DYNAMIC;
> +       fcs->u.dyn.leaves = leaves;
> +       fcs->u.dyn.numbers = numbers;
>       }
>       else
>       {
> 
> I've committed all of your patches as well as this one.

Hmm, the following two patches were not merged are still needed to fix
two memory leaks (unless I'm mistaken).

-- 
Frederic Crozat <fcrozat@xxxxxxxxxxxx>
Mandriva
Index: ChangeLog
===================================================================
RCS file: /cvs/fontconfig/fontconfig/ChangeLog,v
retrieving revision 1.109.2.193
diff -u -p -r1.109.2.193 ChangeLog
--- ChangeLog	11 Apr 2006 14:20:59 -0000	1.109.2.193
+++ ChangeLog	11 Apr 2006 14:46:26 -0000
@@ -1,3 +1,8 @@
+2006-04-11  Frederic Crozat  <fcrozat@xxxxxxxxxxxx>
+
+	* src/fccharset.c: (FcCharSetPutLeaf):
+	Fix memory leak in error case (Coverity defect #1192).
+
 2006-04-11  Patrick Lam  <plam@xxxxxxx>
 	* src/fccharset.c (FcCharSetPutLeaf):
 
Index: src/fccharset.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fccharset.c,v
retrieving revision 1.25.4.14
diff -u -p -r1.25.4.14 fccharset.c
--- src/fccharset.c	11 Apr 2006 14:20:59 -0000	1.25.4.14
+++ src/fccharset.c	11 Apr 2006 14:46:26 -0000
@@ -177,7 +177,10 @@
 	FcMemAlloc (FC_MEM_CHARSET, (fcs->num + 1) * sizeof (FcCharLeaf *));
 	numbers = malloc ((fcs->num + 1) * sizeof (FcChar16));
 	if (!numbers)
+	{
+	    free (leaves);
 	    return FcFalse;
+	}
 	FcMemAlloc (FC_MEM_CHARSET, (fcs->num + 1) * sizeof (FcChar16));
 
 	for (i = 0; i < fcs->num; i++)
Index: ChangeLog
===================================================================
RCS file: /cvs/fontconfig/fontconfig/ChangeLog,v
retrieving revision 1.109.2.193
diff -u -p -r1.109.2.193 ChangeLog
--- ChangeLog	11 Apr 2006 14:20:59 -0000	1.109.2.193
+++ ChangeLog	11 Apr 2006 14:39:32 -0000
@@ -1,3 +1,8 @@
+2006-04-11  Frederic Crozat  <fcrozat@xxxxxxxxxxxx>
+
+	* src/fclang.c: (FcNameUnparseLangSet):
+	Fix another memory leak.
+
 2006-04-11  Patrick Lam  <plam@xxxxxxx>
 	* src/fccharset.c (FcCharSetPutLeaf):
 
Index: src/fclang.c
===================================================================
RCS file: /cvs/fontconfig/fontconfig/src/fclang.c,v
retrieving revision 1.14.4.11
diff -u -p -r1.14.4.11 fclang.c
--- src/fclang.c	11 Apr 2006 14:20:59 -0000	1.14.4.11
+++ src/fclang.c	11 Apr 2006 14:39:32 -0000
@@ -578,6 +578,7 @@ FcNameUnparseLangSet (FcStrBuf *buf, con
                 }
 	    first = FcFalse;
 	}
+	FcStrListDone (list);
     }
     return FcTrue;
 }
_______________________________________________
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