-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add mgos_conf_parse_msg() #553
Conversation
src/mgos_config_util.c
Outdated
mg_asprintf(msg, 0, "[%s] invalid string", path); | ||
LOG(LL_ERROR, (*msg)); | ||
if (ctx->msg) { | ||
*ctx->msg = *msg; |
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.
we need to make sure *msg doesn't leak.
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.
A note saying it should be freed by the caller?
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.
yes, that'd be nice (in the header).
but when it's not provided, we should still not be leaking.
e7a1d90
to
eaeb470
Compare
did you go back to stack buffer + stdup? i think mg_asprintf will still work, we just need to free it on return if the pointer was not provided by the user. will save an extra copy and 100 bytes of stack |
I did indeed. There are too many |
oh no, it should be easier: all you need to do is to have mgos_conf_parse_off always provide non-null ctx.msg to mgos_conf_parse_cb to use but free it before returning if it was a local variable and pass on to the user if it was provided by the user. |
This version of the function is identical to mgos_conf_parse() but allows the caller to get an error message when parsing or data type checks fail.
thanks! |
This version of the function is identical to mgos_conf_parse() but
allows the caller to get an error message when parsing or data type
checks fail.