-
Notifications
You must be signed in to change notification settings - Fork 201
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
parser: plug a memory leak #309
Conversation
The route->type field wasn't being free'ed in case of error. Caught by a unit test compiled with ASAN.
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.
The Route is defined as:
typedef struct {
guint family;
char* type;
char* scope;
guint table;
char* from;
char* to;
char* via;
gboolean onlink;
/* valid metrics are valid positive integers.
* invalid metrics are represented by METRIC_UNSPEC */
guint metric;
guint mtubytes;
guint congestion_window;
guint advertised_receive_window;
} NetplanIPRoute;
We're freeing route->type
here, but what about scope
/from
/to
/via
on error? Should we be using free_route()
util (from types.c
) instead?
Yes, definitely. I didn't pay attention to the fact that the other fields could be allocated later. |
A different error might happen later and we will end up not freeing other fields.
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.
Thanks, having a closer look myself. I think we can further simplify this, by making use of the route_clear()
function (instead of manual free & nullify), as defined using the CLEAR_FROM_FREE(free_route, route_clear, NetplanIPRoute);
macro. Also, the route_clear
function is already declared in types.h
, so no need to add free_route
into types-internal.h
(and no need to make it non-static).
src/parse.c
Outdated
@@ -1993,7 +1993,7 @@ handle_routes(NetplanParser* npp, yaml_node_t* node, const void* _, GError** err | |||
|
|||
err: | |||
if (npp->current.route) { | |||
g_free(npp->current.route); | |||
free_route(npp->current.route); | |||
npp->current.route = NULL; |
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.
Use route_clear()
instead of manual free & nullify.
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.
lgtm, thanks!
The route->type field wasn't being free'ed in case of error. Caught by a unit test compiled with ASAN.
Description
Checklist
make check
successfully.make check-coverage
).