-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix memory leak in lmdb.cc + improve performance while reading collections in resolveMultiMatches #2520
Open
ziollek
wants to merge
4
commits into
owasp-modsecurity:v3/master
Choose a base branch
from
ziollek:v3/master
base: v3/master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix memory leak in lmdb.cc + improve performance while reading collections in resolveMultiMatches #2520
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
064b626
Remove memory leak in lmdb.cc while passing data from MDB_val to Vari…
ziollek f1c5f6b
Optimize fetching collection in resolveMultiMatches
ziollek 440e3c9
Fix static-check violations
ziollek d980bef
Merge branch 'SpiderLabs:v3/master' into v3/master
ziollek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,6 +291,7 @@ void LMDB::resolveSingleMatch(const std::string& var, | |
reinterpret_cast<char *>(mdb_value_ret.mv_data), | ||
mdb_value_ret.mv_size); | ||
VariableValue *v = new VariableValue(&var, a); | ||
delete a; | ||
l->push_back(v); | ||
} | ||
|
||
|
@@ -498,22 +499,28 @@ void LMDB::resolveMultiMatches(const std::string& var, | |
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { | ||
l->insert(l->begin(), new VariableValue( | ||
&m_name, | ||
new std::string(reinterpret_cast<char *>(key.mv_data), | ||
std::string(reinterpret_cast<char *>(key.mv_data), | ||
key.mv_size), | ||
new std::string(reinterpret_cast<char *>(data.mv_data), | ||
std::string(reinterpret_cast<char *>(data.mv_data), | ||
data.mv_size))); | ||
} | ||
} else { | ||
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { | ||
char *a = reinterpret_cast<char *>(key.mv_data); | ||
if (strncmp(var.c_str(), a, keySize) == 0) { | ||
l->insert(l->begin(), new VariableValue( | ||
&m_name, | ||
new std::string(reinterpret_cast<char *>(key.mv_data), | ||
key.mv_size), | ||
new std::string(reinterpret_cast<char *>(data.mv_data), | ||
data.mv_size))); | ||
} | ||
string2val(var, &key); | ||
rc = mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE); | ||
if (rc == 0) { | ||
do { | ||
char *a = reinterpret_cast<char *>(key.mv_data); | ||
if (strncmp(var.c_str(), a, keySize) == 0) { | ||
l->insert(l->begin(), new VariableValue( | ||
&m_name, | ||
std::string(reinterpret_cast<char *>(key.mv_data), | ||
key.mv_size), | ||
std::string(reinterpret_cast<char *>(data.mv_data), | ||
data.mv_size))); | ||
} else { | ||
break; | ||
} | ||
} while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0); | ||
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. replace 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. |
||
} | ||
} | ||
|
||
|
@@ -569,9 +576,9 @@ void LMDB::resolveRegularExpression(const std::string& var, | |
} | ||
|
||
VariableValue *v = new VariableValue( | ||
new std::string(reinterpret_cast<char *>(key.mv_data), | ||
std::string(reinterpret_cast<char *>(key.mv_data), | ||
key.mv_size), | ||
new std::string(reinterpret_cast<char *>(data.mv_data), | ||
std::string(reinterpret_cast<char *>(data.mv_data), | ||
data.mv_size)); | ||
l->insert(l->begin(), v); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@ziollek replace
MDB_SET_RANGE
toMDB_SET_KEY
MDB_SET_RANGE
- getting first key greater than or equal to specified key http://www.lmdb.tech/doc/group__mdb.html#ga1206b2af8b95e7f6b0ef6b28708c9127If you are looking for none exist
samplekey
you get key containingsamplekey
likesamplekey2
(if such key exist)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.
Workable link for @sobczak-m comment's - http://www.lmdb.tech/doc/group__mdb.html#gga1206b2af8b95e7f6b0ef6b28708c9127af9feb0557c2954dbf7732eee5e1b59e7