Skip to content

Commit

Permalink
Fix memory leak in op_send_status_server
Browse files Browse the repository at this point in the history
There is no corresponding `free` for this `malloc` call in
`op_send_status_server`, as `op`s are not recursively `free`d.

Fix it by referring directly to the metadata instead of copying it, as the
metadata will remain alive for the lifetime of the `Op`, see
`withOpArrayAndCtxts`.

Source: awakesecurity#137
  • Loading branch information
mrBliss authored and fumieval committed Jul 18, 2023
1 parent 4e5458a commit 9352490
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions core/cbits/grpc_haskell.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ void op_send_status_server(grpc_op *op_array, size_t i,
grpc_op *op = op_array + i;
op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
op->data.send_status_from_server.trailing_metadata_count = metadata_count;
op->data.send_status_from_server.trailing_metadata
= malloc(sizeof(grpc_metadata)*metadata_count);
memcpy(op->data.send_status_from_server.trailing_metadata, m,
metadata_count*sizeof(grpc_metadata));
op->data.send_status_from_server.trailing_metadata = m;
op->data.send_status_from_server.status = status;
op->data.send_status_from_server.status_details = details;
op->flags = 0;
Expand Down

0 comments on commit 9352490

Please sign in to comment.