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

Why not use unique_ptr<> ? #49

Closed
01e9 opened this issue Jan 2, 2018 · 1 comment
Closed

Why not use unique_ptr<> ? #49

01e9 opened this issue Jan 2, 2018 · 1 comment

Comments

@01e9
Copy link
Contributor

01e9 commented Jan 2, 2018

This is just a question, you can close this issue right away.

The below code is like this for a reason or just a habit?

char *const buf = new char[2*maxlen+1];
try
{
int err = 0;
PQescapeStringConn(m_conn, buf, str, maxlen, &err);
if (err) throw argument_error(err_msg());
escaped = std::string(buf);
}
catch (const std::exception &)
{
delete [] buf;
throw;
}
delete [] buf;

http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#e6-use-raii-to-prevent-leaks

@jtv
Copy link
Owner

jtv commented Jan 2, 2018

You're right — that looks like a case for std::vector<char>. All I can say is I probably wrote this a long, long time ago.

Fixing it now!

@jtv jtv closed this as completed in 715dbab Jan 2, 2018
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

No branches or pull requests

2 participants