Use array delete for point arrays#60
Conversation
|
I was hoping to merge #50 by @dov this week and finally make a new release of aggdraw. It looks like the new version would have this issue too. Maybe I can merge #50 and then we can update this PR to fix these issues. Doing it the other way around (this first then that) may make us lose these changes. @adenyes Great work. Thanks for the PR. Could you tell me what commands you run to generate these warnings so I might run them myself? |
|
@adenyes Any advice for reproducing these messages you were getting? |
|
@djhoese AddressSanitizer is included with clang and gcc these days. The simplest way to enable AddressSanitizer for this module is probably to add the appropriate compiler and linker flags to the Extension constructor parameters in setup.py:168 I run it with an address-sanitizer instrumented python using a custom build chain. If you only want to instrument the module, there may be other steps - linking asan as a DSO, LD_PRELOAD the asan dso from clang's libs, wherever it is on your platform. I have not tried this, though. The errors above were printed during a unit test which includes aggdraw and uses it to draw a line. |
|
Hm I'm having trouble getting this to work on my system. I add the flags to setup.py and get an error when trying to import aggdraw that tells me to do: I tried running our |
|
You might not be getting the error because alloc_dealloc_mismatch is disabled by default on Darwin and Windows though I don't know the reasons behind that. The minimal case is to create a draw object and pen then draw a line. Your graphics self test should hit it. I can provide more specific help after Thursday. Thank you for working on this. |
|
Hm I'll have to switch to linux: Details |
|
Darn, can't get it to work on CentOS 7 with miniconda installed gcc either: Details |
|
Ah ok, test_pen doesn't hit it. |
djhoese
left a comment
There was a problem hiding this comment.
Once I was able to get this working on linux I verified that taking in your modifications and running all of the tests (and analyzing what was changed), this looks good to me.
Thanks for running these checks and fixing everything.
This change uses array delete on PointF arrays allocated by getpoints in aggdraw.cxx.
While doing some testing on a local build made with address sanitizer, I got an error that the allocator and deallocator for points in draw_line didn't match. This looks true to me:
getpoints, returning memory allocated with new PointF[]:
aggdraw/aggdraw.cxx
Line 894 in 66af911
draw_line, calling getpoints and then releasing the PointF using simple delete:
aggdraw/aggdraw.cxx
Line 1190 in 66af911
SUMMARY:
AddressSanitizer: alloc-dealloc-mismatch (/.../libtools_build_sanitizers_asan-ubsan-py.so+0xa06c0) in operator delete(void*, unsigned long)
==1481283==ERROR: AddressSanitizer: alloc-dealloc-mismatch (operator new [] vs operator delete) on 0x603000050f80
SCARINESS: 10 (alloc-dealloc-mismatch)
#0 0x7ff93c34e6c0 in operator delete(void*, unsigned long) (/.../libtools_build_sanitizers_asan-ubsan-py.so+0xa06c0)
#1 0x7ff92b4a7ba4 in draw_line(DrawObject*, _object*) /tmp/pip-wheel-2XAzmg/aggdraw/aggdraw.cxx:1190:16
#2 0x7ff93bfaa2ee in call_function /.../Python-2.7.14/Python/ceval.c:4357:13
0x603000050f80 is located 0 bytes inside of 24-byte region [0x603000050f80,0x603000050f98)
allocated by thread T0 here:
#0 0x7ff93c34d450 in operator new[](unsigned long) (/.../libtools_build_sanitizers_asan-ubsan-py.so+0x9f450)
#1 0x7ff92b4a4c9a in getpoints(_object*, int*) /tmp/pip-wheel-2XAzmg/aggdraw/aggdraw.cxx:894:24
#2 0x7ff92b4a7aff in draw_line(DrawObject*, _object*) /tmp/pip-wheel-2XAzmg/aggdraw/aggdraw.cxx:1183:31
#3 0x7ff93bfaa2ee in call_function /.../Python-2.7.14/Python/ceval.c:4357:13
Testing after this change, address sanitizer seems happy.
Thanks, maintainers!