Variable overwritting issue with a fork version of ardupilot 4.1.5

Hi everyone, I’m developing my own drone using a Pixracer R15 and a forked version of ArduPilot 3.7. I wanted to update my code to version 4.1.5 to use the HereFlow libraries, and everything was working fine. However, after 2 minutes of flight, my drone crashed. Upon checking the log, I noticed that some variables used to estimate the motor output were completely absurd, with the height estimation variable jumping from 1 meter to 3.24E285. The PM section of the log also showed that the memory was running low, which led me to suspect that I have a memory issue and that my variables are being overwritten.

Interestingly, I did not experience this issue with the 3.7 version, and I have not made significant changes to the code. I have encountered this same problem in multiple flights, but at different times, and the only common factor seems to be the low memory (around 3000B left).

Has anyone had a similar issue with version 4.1.5? Any tips on how I can debug this issue? I would greatly appreciate any help or advice on how to resolve this problem. Thank you.