xdo_search: fix improper memfrees, pre-compile regexes optimization#407
Open
Cycatz wants to merge 1 commit intojordansissel:masterfrom
Open
xdo_search: fix improper memfrees, pre-compile regexes optimization#407Cycatz wants to merge 1 commit intojordansissel:masterfrom
Cycatz wants to merge 1 commit intojordansissel:masterfrom
Conversation
Original author: Peter Wu <lekensteyn@gmail.com> Modified by: Cycatz <thesummernightcat@gmail.com> If any of compile_re statements fails, all uninitialized regex_t objects are freed due to short-circuit evaluation, which causing segmentation faults. Now they are initialized to zero with memset and besides that, all regexes are now pre-compiled before iterating through all windows. (as a side-effect of the optimization: return early when a regex fails to compile). Other changes: constantify regex_t* where applicable.
Contributor
|
This is one of those cases where one would usually use a goto, but given we don't have a single goto in there ATM, i doubt this would be well received. I think i would prefer the much simpler tweak, although it could rightfully be considered looking ugly and annoyingly repetitive: Just a thought. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The patch was originally from @Lekensteyn at this commit in #36, I merged it with HEAD and also made some changes.
The commit fixes #258, which is causing by freeing uninitialized
regex_tobjects due to short-circuit evaluation.The regex pre-compiled solution initializes the content of these
regex_tobjects to zero usingmemsetso thatregfrees don't crash.In addition, the origin patch also resolves the issue of repeated error messages by compiling
regex_tobjects at start. These are all done by @Lekensteyn, awesome!Aside from resolving merging conflicts, I add
regex_tstruct for role, renamexdg_search_retoxdg_regex_tfor style consistency and apply the changes that constantify regex_t* where applicable from @Lekensteyn.BTW, I remove the whitespaces removal code changes, I think it should be made in other commit. If there is any need, I can help with that.