LibreCAD / libdxfrw

Successor of https://sourceforge.net/projects/libdxfrw/, developed for LibreCAD, by LibreCAD Contributors, usable for all
GNU General Public License v2.0
198 stars 75 forks source link

Memory leak in dwg2dxf #18

Open ghost opened 4 years ago

ghost commented 4 years ago

When converting the file Ceco.NET-Architecture-Tm-271.dwg obtained from here with dwg2dxf 1.0.1 it consumes memory at a rate of 1GB every 5 seconds or so and appears to have no limit (I killed it after 40GB)

Akaame commented 3 years ago

This is not a memory leak.

I run the code in debug mode and the line here reports

https://github.com/LibreCAD/libdxfrw/blob/16642a70cb8865742467f6bc1d8c3618deee8432/src/drw_entities.cpp#L1910

470484544 ncontrol for a spline in the hatch. Considering this creates a shared pointer to a DRW_Coord object spline's control list would hog like 13 GBs of memory. But the problem obviously is not the memory here nor the file itself (I do not think it is corrupted or anything). The convertor does not have this problem for CADs without hatch type object. The section (L1900 to L 1918 in the file above) that adds the spline must be revisited.

Other CAD files from Villa Savoye suffer from the same problem.

Akaame commented 3 years ago

The issue turned out be a parsing error as I suspected. I used the DWG file spec found here to make a comparison with the actual code and there appears to be two mistakes in both this branch and to the mainline code in the SourceForge. Below is the simple patch file created by git diff of the fix.

libdxfrw_18.patch.zip

Steps:

  1. Get the mainline codebase
  2. Add the following files to the new code base from this fork: libdxfrw.dox, CMakeLists.txt, src/main_doc.h, dwg2dxf/CMakeLists.txt
  3. Apply the patch
  4. Run cmake and make in build as stated in README.md of this branch
  5. build/dwg2dxf/dwg2dxf path/to/dwg path/to/output_dxf

Cheers.