← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Fix memory leaks with improper wxBaseConfig* usage (model ownership and ownership-transfer with std::unique_ptr)

 

-        wxConfigBase* config = GetNewConfig( fn.GetFullPath() );
+        auto config = GetNewConfig( fn.GetFullPath() );
          config->Write( HOTKEYS_CONFIG_KEY, msg );
-        delete config;
This has subtle potential for errors -- while I'm normally in favour of
using "auto", spelling it out would help here in case the function
signature is changed back.
Yes, I can see the risk. I'd ideally ask for the coding guide to explicitly state that raw pointers are not allowed in new code where ownership-transfers happens. A change back would violate that, and over time old code should be updated. With these leaks you see what happens if you pass around raw pointers and communicate the intent only through comments (The comment on GetNewComment explicitly stated the caller is responsible for deleting the returned object).


Follow ups

References