Conversation
| git__free(var_value); | ||
| git__strtolower(name); | ||
| git_buf_printf(&buf, "%s.%s", current_section, name); | ||
| git__free(name); |
There was a problem hiding this comment.
It seems disappointing to have to do an extra tiny malloc here for name n every variable that we read and immediately free it. Doing a little bit more manipulation and not doing a printf here might help. eg:
git_buf_puts(&buf, current_section);
git_buf_putc(&buf, '.');
for (c = name, *c; c++)
git_buf_putc(&buf, git__tolower(*c));
There was a problem hiding this comment.
Agreed. Your solution looks a lot cleaner, thanks!
a0c5029 to
81da513
Compare
|
Improved as to @ethomson's proposal |
|
|
||
| if (git_buf_oom(&buf)) { | ||
| git__free(var_value); | ||
| git_buf_free(&buf); |
There was a problem hiding this comment.
There's no need to free an OOM'd buffer. If the realloc fails, we free the buffer we had before setting the buffer to the OOM one.
There was a problem hiding this comment.
Yeah, obviously. I've created a new commit for that, as there is also a second occasion where we had the same pattern nearby. Thanks for pointing out.
a2bff86 to
a59bb70
Compare
a59bb70 to
c3b4e1d
Compare
|
Rebased to fix conflicts |
The function `git_config_parse` uses several callbacks to pass data along to the caller as it parses the file. One design shortcoming here is that strings passed to those callbacks are expected to be freed by them, which is really confusing. Fix the issue by changing memory ownership here. Instead of expecting the `on_variable` callbacks to free memory for `git_config_parse`, just do it inside of `git_config_parse`. While this obviously requires a bit more memory allocation churn due to having to copy both name and value at some places, this shouldn't be too much of a burden.
The `parse_variable` function has two out parameters `var_name` and `var_value`. Currently, those are not being sanitized to `NULL`. when. any error happens inside of the `parse_variable` function. Fix that. While at it, the coding style is improved to match our usual coding practices more closely.
Buffers which ran out of memory will never have any memory attached to them. As such, it is not necessary to call `git_buf_free` if the buffer is out of memory.
c3b4e1d to
e1e90dc
Compare
|
Rebased again to fix conflicts |
|
🎉 |
Two small cleanups to make code more readable in our config parser.