Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hmacdope opened this issue Jul 15, 2024 · 1 comment · May be fixed by #5
Open

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

hmacdope opened this issue Jul 15, 2024 · 1 comment · May be fixed by #5

Comments

@hmacdope
Copy link
Member

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` instead.

@richardjgowers
Copy link
Member

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

@hmacdope hmacdope linked a pull request Jul 16, 2024 that will close this issue
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 a pull request may close this issue.

2 participants