Skip to content

Fix memory leaks & remove a dubious cast#12

Merged
adbancroft merged 8 commits intomasterfrom
casts_leaks
Mar 19, 2026
Merged

Fix memory leaks & remove a dubious cast#12
adbancroft merged 8 commits intomasterfrom
casts_leaks

Conversation

@adbancroft
Copy link
Copy Markdown
Owner

  1. OverrideableProxiedArduinoFake_t::getFake uses a static_cast to potentially cross cast a fakeit::Mock. E.g. from fakeit::Mock<Stream> to fakeit::Mock<Print>. This isn't valid since fakeit::Mock is a template class and there is no relationship between mocked types. I.e. even though Stream is derived from Print, fakeit::Mock<Stream> is not derived from fakeit::Mock<Print> (dynamic_cast would return nullptr). Fixed using an inherited interface: IFake
  2. ArduinoFakeMock was returning a heap allocated object, resulting in memory leaks. Changed to return a std::shared_ptr

@adbancroft adbancroft merged commit f02872e into master Mar 19, 2026
6 checks passed
@adbancroft adbancroft deleted the casts_leaks branch March 19, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant