-
Notifications
You must be signed in to change notification settings - Fork 76
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
Memory leaks #137
Comments
Hi, thank you for creating this ticket! |
mrBliss
added a commit
to mrBliss/gRPC-haskell
that referenced
this issue
Sep 28, 2022
There is no corresponding `free` for this `malloc` call in `op_send_initial_metadata`, 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
mrBliss
added a commit
to mrBliss/gRPC-haskell
that referenced
this issue
Sep 28, 2022
There is no corresponding `grpc_byte_buffer_destroy` for this `grpc_byte_buffer_copy` call in `op_send_message`, as `op`s are not recursively `free`d. Fix it by referring directly to the byte buffer instead of copying it, as the byte buffer will remain alive for the lifetime of the `Op`, see `withOpArrayAndCtxts`. Source: awakesecurity#137
mrBliss
added a commit
to mrBliss/gRPC-haskell
that referenced
this issue
Oct 7, 2022
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
Closed
fumieval
pushed a commit
to fumieval/gRPC-haskell
that referenced
this issue
Jun 22, 2023
There is no corresponding `free` for this `malloc` call in `op_send_initial_metadata`, 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
fumieval
pushed a commit
to fumieval/gRPC-haskell
that referenced
this issue
Jun 22, 2023
There is no corresponding `grpc_byte_buffer_destroy` for this `grpc_byte_buffer_copy` call in `op_send_message`, as `op`s are not recursively `free`d. Fix it by referring directly to the byte buffer instead of copying it, as the byte buffer will remain alive for the lifetime of the `Op`, see `withOpArrayAndCtxts`. Source: awakesecurity#137
fumieval
pushed a commit
to fumieval/gRPC-haskell
that referenced
this issue
Jun 22, 2023
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
fumieval
pushed a commit
to fumieval/gRPC-haskell
that referenced
this issue
Jul 18, 2023
There is no corresponding `free` for this `malloc` call in `op_send_initial_metadata`, 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
fumieval
pushed a commit
to fumieval/gRPC-haskell
that referenced
this issue
Jul 18, 2023
There is no corresponding `grpc_byte_buffer_destroy` for this `grpc_byte_buffer_copy` call in `op_send_message`, as `op`s are not recursively `free`d. Fix it by referring directly to the byte buffer instead of copying it, as the byte buffer will remain alive for the lifetime of the `Op`, see `withOpArrayAndCtxts`. Source: awakesecurity#137
fumieval
pushed a commit
to fumieval/gRPC-haskell
that referenced
this issue
Jul 18, 2023
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
ixmatus
pushed a commit
that referenced
this issue
Jul 18, 2023
* Fix memory leak in op_send_initial_metadata There is no corresponding `free` for this `malloc` call in `op_send_initial_metadata`, 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: #137 * Fix memory leak in op_send_message There is no corresponding `grpc_byte_buffer_destroy` for this `grpc_byte_buffer_copy` call in `op_send_message`, as `op`s are not recursively `free`d. Fix it by referring directly to the byte buffer instead of copying it, as the byte buffer will remain alive for the lifetime of the `Op`, see `withOpArrayAndCtxts`. Source: #137 * Work around memory leak in `createOpContext` According to valgrind, a `grpc_slice` created by `grpc_slice_malloc_` (called via `C.grpcSliceMalloc` in the `OpRecvStatusOnClient` case of `createOpContext`) is leaked: ``` 72 bytes in 1 blocks are definitely lost in loss record 8 of 11 at 0x484079B: malloc (in /nix/store/73if83n79h4ml8rcb473ym47zmb4vi5x-valgrind-3.19.0/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) by 0x4BD2ACD: gpr_malloc (in /nix/store/kfbhv9kid1dzblf16w9g1i10x48xkyrr-grpc-1.34.1/lib/libgpr.so.14.0.0) by 0x4AC3864: grpc_core::UnmanagedMemorySlice::HeapInit(unsigned long) (in /nix/store/kfbhv9kid1dzblf16w9g1i10x48xkyrr-grpc-1.34.1/lib/libgrpc.so.14.0.0) by 0x4AC3AC0: grpc_slice_malloc (in /nix/store/kfbhv9kid1dzblf16w9g1i10x48xkyrr-grpc-1.34.1/lib/libgrpc.so.14.0.0) by 0x41DCD1: grpc_slice_malloc_ (in ..) by 0x48D758: grpczmleakzm0zi0zi1zminplace_NetworkziGRPCziLowLevelziOp_createOpContext1_info (in ..) ``` However, we actually try to free this slice using `free_slice` in `freeOpContext`, so this is unexpected. Note that `grpc_slice` stores its payload on the heap and maintains its own reference count, unless the payload is small enough to be stored inline. Perhaps there is still an unknown reference to it somewhere, which keeps the `grpc_slice` alive. I haven't found out why. I did discover that decreasing `defaultStatusStringLen` and thus the size of the slice made the memory leak disappear. I believe because a smaller size means that no extra heap allocation is necessary and the payload can be stored inline. As the comment on `defaultStatusStringLen` says that "gRPC actually ignores this length and reallocates a longer string if necessary", decreasing its size should be safe. * Fix memory leak in op_send_status_server 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: #137 --------- Co-authored-by: Thomas Winant <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I'm trying to include this library in grpc_bench. However, there were some critical memory leaks that failed the bench.
Reproduce
Example server code: LesnyRumcajs/grpc_bench#243
Start server:
A simple request:
Valgrind output:
Leaks
grpc_byte_buffer_copy
fromop_send_message
seems redundantmalloc
fromop_send_initial_metadata
malloc
fromop_send_status_server
memory allocated bymalloc
fromgrpc_completion_queue_pluck_
The text was updated successfully, but these errors were encountered: