Skip to content

Commit

Permalink
qapi: fix memleak by adding implict struct functions in dealloc visitor
Browse files Browse the repository at this point in the history
Otherwise member "base" is leaked in a qapi_free_STRUCTURE() call.

Signed-off-by: Wenchao Xia <[email protected]>
Reviewed-by: Eric Blake <[email protected]>
Message-id: [email protected]
Cc: [email protected]
Signed-off-by: Anthony Liguori <[email protected]>
  • Loading branch information
Wenchao Xia authored and Anthony Liguori committed Nov 6, 2013
1 parent 7d57951 commit 3dce9ca
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions qapi/qapi-dealloc-visitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ static void qapi_dealloc_end_struct(Visitor *v, Error **errp)
}
}

static void qapi_dealloc_start_implicit_struct(Visitor *v,
void **obj,
size_t size,
Error **errp)
{
QapiDeallocVisitor *qov = to_qov(v);
qapi_dealloc_push(qov, obj);
}

static void qapi_dealloc_end_implicit_struct(Visitor *v, Error **errp)
{
QapiDeallocVisitor *qov = to_qov(v);
void **obj = qapi_dealloc_pop(qov);
if (obj) {
g_free(*obj);
}
}

static void qapi_dealloc_start_list(Visitor *v, const char *name, Error **errp)
{
QapiDeallocVisitor *qov = to_qov(v);
Expand Down Expand Up @@ -162,6 +180,8 @@ QapiDeallocVisitor *qapi_dealloc_visitor_new(void)

v->visitor.start_struct = qapi_dealloc_start_struct;
v->visitor.end_struct = qapi_dealloc_end_struct;
v->visitor.start_implicit_struct = qapi_dealloc_start_implicit_struct;
v->visitor.end_implicit_struct = qapi_dealloc_end_implicit_struct;
v->visitor.start_list = qapi_dealloc_start_list;
v->visitor.next_list = qapi_dealloc_next_list;
v->visitor.end_list = qapi_dealloc_end_list;
Expand Down

0 comments on commit 3dce9ca

Please sign in to comment.