New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed segmentation fault in Path workbench #9339
Conversation
@evils, ping. |
if (m_toolShape.empty()) | ||
return 0.0f; | ||
|
||
toolShapePoint test; | ||
test.radiusPos = std::abs(pos) * radius; | ||
|
||
auto it = std::lower_bound(m_toolShape.begin(), m_toolShape.end(), test, toolShapePoint::less_than()); | ||
return it->heightPos; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cause of the crash was it
being null and still being dereferenced. This is still a possibility if all values in m_toolShape
are < test
. See https://en.cppreference.com/w/cpp/algorithm/lower_bound. It appears they need m_toolShape
to be sorted (or a looser condition defined in the link) before it can be run. If that is already satisfied, the following changes are good to go. If not, there may be a need to do the sorting here (which may be expensive) or elsewhere.
if (m_toolShape.empty()) | |
return 0.0f; | |
toolShapePoint test; | |
test.radiusPos = std::abs(pos) * radius; | |
auto it = std::lower_bound(m_toolShape.begin(), m_toolShape.end(), test, toolShapePoint::less_than()); | |
return it->heightPos; | |
} | |
toolShapePoint test; | |
test.radiusPos = std::abs(pos) * radius; | |
auto it = std::lower_bound(m_toolShape.begin(), m_toolShape.end(), test, toolShapePoint::less_than()); | |
if (it == m_toolShape.end()) | |
return 0.0; | |
return it->heightPos; | |
} |
@@ -783,14 +783,14 @@ cSimTool::cSimTool(const TopoDS_Shape& toolShape, float res){ | |||
|
|||
float cSimTool::GetToolProfileAt(float pos) // pos is -1..1 location along the radius of the tool (0 is center) | |||
{ | |||
try{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the try is probably OK, unless the comparison itself can raise exceptions. If it does the catch should also have reported the text of those.
Thank you, AjinkyaDahale. Within the try catch there was, simply put, comparison of floats. I found usage of try&catch to compare floats redundant. |
I haven't tested it yet, but the changes seem fine. @xtemp09 can you confirm the list is sorted? |
@AjinkyaDahale, the lines 748-775 populate So, yes, it's sorted. |
Could you add a note there (or in the documentation in the header file) mentioning "this must stay sorted for so-and-so reasons" so that if in the future someone creates a non-sorting algorithm, adjustments can be made. |
Done. When running the simulation I found out that the memory allocated for simulation is not deallocated at all. SUMMARY: LeakSanitizer: 32148253 byte(s) leaked in 6768 allocation(s). |
Please clarify. Is this another outstanding issue? Are you resolving it? |
@xtemp09 an aside, would you be open to writing a tutorial on how you find leaks so other devs or testers (who don't know) can benefit from utilizing this approach when working on FreeCAD codebase ? |
sliptonic, luzpaz, I just ran the input files from the issue #6286 and found that the memory allocated to perform simulation is not deallocated at all. I'm not working on it, because I don't know the mixture of Python and C++ memory model used in FreeCAD. Somebody wiser than me should be dealing with this. Here is the complete leak-report.txt. Compiled with gcc-12.1 with LSAN, linked against release Python library on Ubuntu 22.04. The following command was used to compile FreeCAD to find memory leakscmake .. -G Ninja \
-D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_INSTALL_PREFIX=/home/xtemp09/mem-test/ \
-D BUILD_ARCH=Off \
-D BUILD_FEM=Off \
-D BUILD_OPENSCAD=Off \
-D BUILD_INSPECTION=Off \
-D BUILD_PATH=On \
-D BUILD_REVERSEENGINEERING=Off \
-D BUILD_ROBOT=On \
-D CMAKE_C_FLAGS_DEBUG="-g -Og -fsanitize=leak -fno-omit-frame-pointer -fuse-ld=mold -Wno-deprecated" \
-D CMAKE_CXX_FLAGS_DEBUG="-g -Og -fsanitize=leak -fno-omit-frame-pointer -fuse-ld=mold -Wno-deprecated" If one knows Python, he can add the option -D PYTHON_LIBRARY_DEBUG=/usr/lib/x86_64-linux-gnu/libpython3.10d.so When you close a program compiled with leak sanitizer, the leak report goes to the output. I run FreeCAD with the following command:
to output the report into a file. |
My commentary above provides the command I used to compile FreeCAD to find the memory leaks I mentioned. It works with This configuration works with clangcmake .. -G Ninja \
-D CMAKE_BUILD_TYPE=Debug \
-D CMAKE_INSTALL_PREFIX=/home/xtemp09/path-test/ \
\
-D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ \
-D CMAKE_C_FLAGS_DEBUG="-glldb -fsanitize=leak -fno-omit-frame-pointer" \
-D CMAKE_CXX_FLAGS_DEBUG="-glldb -fsanitize=leak -fno-omit-frame-pointer" \
-D LINK_FLAGS_DEBUG="-fsanitize=leak -fuse-ld=mold" \
\
-D PYTHON_LIBRARY_DEBUG=/usr/lib/x86_64-linux-gnu/libpython3.10d.so \
\
-D CMAKE_AR=/usr/lib/llvm-16/bin/llvm-ar \
-D CMAKE_ADDR2LINE=/usr/lib/llvm-16/bin/llvm-addr2line \
-D CMAKE_MT=/usr/lib/llvm-16/bin/llvm-mt \
-D CMAKE_NM=/usr/lib/llvm-16/bin/llvm-nm \
-D CMAKE_OBJCOPY=/usr/lib/llvm-16/bin/llvm-objcopy \
-D CMAKE_OBJDUMP=/usr/lib/llvm-16/bin/llvm-objdump \
-D CMAKE_RANLIB=/usr/lib/llvm-16/bin/llvm-ranlib \
-D CMAKE_READELF=/usr/lib/llvm-16/bin/llvm-readelf \
-D CMAKE_RC_COMPILER=/usr/lib/llvm-16/bin/llvm-rc \
-D CMAKE_STRIP=/usr/lib/llvm-16/bin/llvm-strip |
Ok. Thanks. Then I'm inclined to merge this PR. Will please open a new issue to focus on the memory issue so it doesn't get lost? |
@sliptonic, I've created the forum topic. |
You can go straight to a github issue. And mention this PR |
Thanks everyone. |
Closes #6286. This commit fixes segmentation fault in Path workbench.
dubstar-04 introduced the code causing segmentation fault. Later, he removed the debug log and then added try and catch.
evils reported crash in the same issue. The crash occured in the same line of code and everything works if my commit is applied.
I removed try and catch, because I think it is not necessary when comparing two floats.
Standard form
Thank you for creating a pull request to contribute to FreeCAD! Place an "X" in between the brackets below to "check off" to confirm that you have satisfied the requirement, or ask for help in the FreeCAD forum if there is something you don't understand.
Please remember to update the Wiki with the features added or changed once this PR is merged.
Note: If you don't have wiki access, then please mention your contribution on the 1.0 Changelog Forum Thread.