MDAnalysis / omnireader

0 stars 0 forks source link

Don't return raw pointers to readers with `GetReader` #1

Open hmacdope opened 3 months ago

hmacdope commented 3 months ago
namespace OmniReader {
    Reader *GetReader(OmniReader::Format option) {
      switch (option) {
        case OmniReader::Format::PlainText:
          return new PlainTextReader();
        case OmniReader::Format::BZ2:
          return new BZ2Reader();
        case OmniReader::Format::GZ:
          return new GZReader();
        default:
          return nullptr;

Has a high chance of leaking memory due to using a raw pointer for the reader. We should use a std::shared_ptr<XReader> or `std::unique_ptr<XReader> instead.

richardjgowers commented 3 months ago

I've never actually used fancy pointers.... If you do a PR and it doesn't nudge perf then sure