kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #32313
Re: [PATCH] fix double free and memory leak in SHAPE_POLY_SET
-
To:
<kicad-developers@xxxxxxxxxxxxxxxxxxx>
-
From:
Maciej Sumiński <maciej.suminski@xxxxxxx>
-
Date:
Fri, 8 Dec 2017 14:56:55 +0100
-
Authentication-results:
spf=pass (sender IP is 188.184.36.48) smtp.mailfrom=cern.ch; lists.launchpad.net; dkim=none (message not signed) header.d=none;lists.launchpad.net; dmarc=bestguesspass action=none header.from=cern.ch;
-
In-reply-to:
<75c75cba-1610-228b-1321-2cdbd78dea51@andreasbuhr.de>
-
Spamdiagnosticmetadata:
NSPM
-
Spamdiagnosticoutput:
1:99
-
User-agent:
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0
Hi Andreas,
Thank you for the patch. The proposed changes are reasonable, therefore
I merged your patch to the master branch.
Cheers,
Orson
On 12/08/2017 12:37 PM, Andreas Buhr wrote:
> Dear Kicad developers,
>
> the attached patch fixes two bugs in SHAPE_POLY_SET.
>
> There were two problems in the triangulation caching
> of SHAPE_POLY_SET:
> First there was a double free:
> While SHAPE_POLY_SET implements the copy constructor,
> it did not implement the operator=, which resulted
> in the default operator= being generated by the
> compiler. The default operator= copied the member
> m_triangulatedPolys, which is a std::vector of pointers.
> So after operator= execution, there are two SHAPE_POLY_SET
> having pointers to the same TRIANGULATED_POLYGONs, each
> of them deleting them in their destructors. This led
> to segfaults, because calling
> TransformShapeWithClearanceToPolygon on a Zone
> uses operator= to copy the contained SHAPE_POLY_SET.
> The new SHAPE_POLY_SET then went out of scope and
> deleted the cached triangulation within the Zone.
>
> This first problem is fixed by implementing operator=
> for SHAPE_POLY_SET.
>
> Second, there was a memory leak: Calling
> "CacheTriangulation" on a SHAPE_POLY_SET,
> then changing the polygon and then calling
> "CacheTriangulation" again led to
> leaking the
> triangulations generated in the first call.
>
> This second problem is fixed by holding
> the cached triangulations in a unique_ptr.
>
> I hope you find this patch useful.
>
> Cheers,
> Andreas
>
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
Attachment:
signature.asc
Description: OpenPGP digital signature
References