You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@me-no-dev I think I've found a potential bug in my PR #4443.
Accidentally, I've created a local helper function in my project where I accept fs::SPIFFSFS as parameter - you can see: I forgot the reference. The correct declaration for my helper function parameter would have been fs::SPIFFSFS &. It cost me an hour of debugging because the compiler didn't spit out any error or warning. The error was a heap corruption.
While normally one should not copy fs::SPIFFSFS because obviously it can have unintended side effects, it did happen to me.
I don't know the implementation details of that class, but it could be PR #4443 is the root cause:
There is no copy constructor defined, so the compiler generates the default one. The default copy constructor will plainly copy all POD types and this happens to the member variable pointer partitionLabel_. Then, when the local helper function in my project is returning, the destructor is called, the heap will be freed and now in the original instance, partitionLabel_ points to invalid heap memory.
There are the following solutions to this:
Delete the default copy constructor and default operator= (maybe also their move semantics counterpart)
Implement proper constructors/operators which copy the pointer correctly
Use smart pointers from the C++ std lib (though I am not sure this is a dependency Arduino Core wants to have?)
Re-introduce the String object which I used in the orignal commit of that PR
I am in favor of 4. Please let me know which solution you prefer and I can create a PR for this.
The text was updated successfully, but these errors were encountered:
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
@me-no-dev I think I've found a potential bug in my PR #4443.
Accidentally, I've created a local helper function in my project where I accept
fs::SPIFFSFS
as parameter - you can see: I forgot the reference. The correct declaration for my helper function parameter would have beenfs::SPIFFSFS &
. It cost me an hour of debugging because the compiler didn't spit out any error or warning. The error was a heap corruption.While normally one should not copy
fs::SPIFFSFS
because obviously it can have unintended side effects, it did happen to me.I don't know the implementation details of that class, but it could be PR #4443 is the root cause:
There is no copy constructor defined, so the compiler generates the default one. The default copy constructor will plainly copy all POD types and this happens to the member variable pointer
partitionLabel_
. Then, when the local helper function in my project is returning, the destructor is called, the heap will be freed and now in the original instance,partitionLabel_
points to invalid heap memory.There are the following solutions to this:
move semantics
counterpart)String
object which I used in the orignal commit of that PRI am in favor of 4. Please let me know which solution you prefer and I can create a PR for this.
The text was updated successfully, but these errors were encountered: