PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
7.85k stars 13.22k forks source link

[Bug] "differential_drive stop" produces Segmentation fault #22818

Open slgrobotics opened 4 months ago

slgrobotics commented 4 months ago

Describe the bug

When running a "_make px4_sitl gz_r1rover" (or _gzlawnmower) differential_drive module runs at startup by the rc.rover_differential_apps

If user wants to stop the module, by "_differentialdrive stop" - a Segmentation fault happens and whole PX4 program quits.

@PerFrivik @MaEtUgR @dagar - issue created per your request

To Reproduce

pxh> differential_drive stop

... Segmentation fault

Expected behavior

The module should stop and could be started again

Screenshot / Media

No response

Flight Log

no log needed

Software Version

current main

Flight controller

N/A - sitl

Vehicle type

Rover

How are the different components wired up (including port information)

No response

Additional context

No response

MaEtUgR commented 4 months ago

Thanks for the issue! I started testing during the dev call and so far I found:

PerFrivik commented 4 months ago

Thanks, I'll take a look!

matteodelseppia commented 1 month ago

I think I fixed the segmentation fault. You just have to add a return statement after the exit_and_cleanup() (line 68 of DifferentialDrive.cpp), otherwise it will try to update the current parameters even if the memory for the module has already been freed.

    if (should_exit()) {
        ScheduleClear();
        exit_and_cleanup();
                return; // < add this
    }

Can I try to pull this?