-
Notifications
You must be signed in to change notification settings - Fork 611
Replace manual memory management with RAII containers #10926
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -722,15 +722,15 @@ String IdoMysqlConnection::Escape(const String& s) | |||
| String utf8s = Utility::ValidateUTF8(s); | ||||
|
|
||||
| size_t length = utf8s.GetLength(); | ||||
| auto *to = new char[utf8s.GetLength() * 2 + 1]; | ||||
|
|
||||
| m_Mysql->real_escape_string(&m_Connection, to, utf8s.CStr(), length); | ||||
| String to; | ||||
| to.GetData().resize(length * 2 + 1); | ||||
|
|
||||
| String result = String(to); | ||||
| size_t escapedLength = m_Mysql->real_escape_string(&m_Connection, to.GetData().data(), utf8s.CStr(), length); | ||||
|
|
||||
| delete [] to; | ||||
|
Comment on lines
-729
to
-731
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we set the SQL mode to a known value without
Otherwise IDO wouldn't function, with or without this change, even if the output was always initialized with
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||
| to.GetData().resize(escapedLength); | ||||
|
|
||||
| return result; | ||||
| return to; | ||||
| } | ||||
|
|
||||
| Dictionary::Ptr IdoMysqlConnection::FetchRow(const IdoMysqlResult& result) | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised that this PR does not remove any
free()calls, but there aren't any for these. Does that mean that this fixes a memory leak (technically, it should only leak the allocation when exiting the process, so not something you would really notice)? Or asking differently: did someone check that thesefree()calls were just missing (there would be a possibility that there was an API that wants amalloc()-allocated pointer and takes ownership of it, at first glance, this doesn't look like this here, but better double-check it)?(This is just a question for the moment, request changes is for the other comment.)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was relying on
Process::IOThreadProc()running for the entire program duration (thefor(;;)loop is never escaped) and only ever usingrealloc()to allocate and free previous allocations. So yes, this had a memory leak, but it's only ever the last allocation that never gets deallocated when the program shuts down.This doesn't really fix that though, since the for loop is still never escaped so the RAII doesn't really do anything here. Also this means the threads are never joined, which probably isn't ideal either... 🤦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't want to put a focus on fixing a more or less theoretical memory leak here, just on making sure that the
free()wasn't missing intentionally.