From 41646238443a34f7c4856c89327e7d304e4ffe8b Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Fri, 22 Nov 2019 00:47:55 +0100 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20free=20op=20array=20values=20in?= =?UTF-8?q?=20op=5Farray=5Fdestroy=20(#98)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These values are all already freed in freeOpContext and doing it twice is an error, see #91 --- core/cbits/grpc_haskell.c | 29 ++--------------------------- core/src/Network/GRPC/Unsafe/Op.chs | 4 ---- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/core/cbits/grpc_haskell.c b/core/cbits/grpc_haskell.c index 51c21a0..ebbcbb1 100644 --- a/core/cbits/grpc_haskell.c +++ b/core/cbits/grpc_haskell.c @@ -210,33 +210,8 @@ void op_array_destroy(grpc_op* op_array, size_t n){ #ifdef GRPC_HASKELL_DEBUG printf("C wrapper: entered op_array_destroy\n"); #endif - for(int i = 0; i < n; i++){ - grpc_op* op = op_array + i; - switch (op->op) { - case GRPC_OP_SEND_INITIAL_METADATA: - metadata_free(op->data.send_initial_metadata.metadata); - break; - case GRPC_OP_SEND_MESSAGE: - grpc_byte_buffer_destroy(op->data.send_message.send_message); - break; - case GRPC_OP_SEND_CLOSE_FROM_CLIENT: - break; - case GRPC_OP_SEND_STATUS_FROM_SERVER: - grpc_haskell_free("op_array_destroy: GRPC_OP_SEND_STATUS_FROM_SERVER", - op->data.send_status_from_server.trailing_metadata); - grpc_haskell_free("op_array_destroy: GRPC_OP_SEND_STATUS_FROM_SERVER", - (char*)(op->data.send_status_from_server.status_details)); - break; - case GRPC_OP_RECV_INITIAL_METADATA: - break; - case GRPC_OP_RECV_MESSAGE: - break; - case GRPC_OP_RECV_STATUS_ON_CLIENT: - break; - case GRPC_OP_RECV_CLOSE_ON_SERVER: - break; - } - } + // This only destroys the array, the values in the array + // are freed in freeOpContext grpc_haskell_free("op_array_destroy", op_array); } diff --git a/core/src/Network/GRPC/Unsafe/Op.chs b/core/src/Network/GRPC/Unsafe/Op.chs index fd8bc01..5dd1a7d 100644 --- a/core/src/Network/GRPC/Unsafe/Op.chs +++ b/core/src/Network/GRPC/Unsafe/Op.chs @@ -47,10 +47,6 @@ deriving instance Show OpArray -- | Destroys an 'OpArray' of the given size. {#fun unsafe op_array_destroy as ^ {`OpArray', `Int'} -> `()'#} --- | brackets creating and destroying an 'OpArray' with the given size. -withOpArray :: Int -> (OpArray -> IO a) -> IO a -withOpArray n f = bracket (opArrayCreate n) (flip opArrayDestroy n) f - -- | Creates an op of type GRPC_OP_SEND_INITIAL_METADATA at the specified -- index of the given 'OpArray', containing the given -- metadata. The metadata is copied and can be destroyed after calling this