[Fontconfig] strange code in FcCharSetPutLeaf (spotted by
Coverity)
Frederic Crozat
fcrozat at mandriva.com
Tue Apr 11 08:06:48 PDT 2006
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 at mandriva.com>
Mandriva
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fontconfig-2.3.94-fccharsetmemleak.patch
Type: text/x-patch
Size: 1182 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20060411/0273c174/fontconfig-2.3.94-fccharsetmemleak.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fontconfig-2.3.94-fclangmemleak2.patch
Type: text/x-patch
Size: 981 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/fontconfig/attachments/20060411/0273c174/fontconfig-2.3.94-fclangmemleak2.bin
More information about the Fontconfig
mailing list