You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2020/10/22 15:52:28 UTC

[GitHub] [pulsar] merlimat commented on a change in pull request #8325: [Issue 8311][pulsar-client-go] Fix memory leak in cgo golang client

merlimat commented on a change in pull request #8325:
URL: https://github.com/apache/pulsar/pull/8325#discussion_r510272691



##########
File path: pulsar-client-go/pulsar/c_producer.go
##########
@@ -298,6 +298,7 @@ func pulsarProducerSendCallbackProxyWithMsgID(res C.pulsar_result, messageId *C.
 		sendCallback.callback(getMessageId(messageId), newError(res, "Failed to send message"))
 	} else {
 		sendCallback.callback(getMessageId(messageId), nil)
+		C.pulsar_message_id_free(messageId)

Review comment:
       @bschofield I think this free should not be done, because `getMessageId(messageId)` is already attaching a finalizer to the Go object and it will free the message id automatically:
   
   ```
   func getMessageId(messageId *C.pulsar_message_id_t) MessageID {
   	msgId := &messageID{ptr: messageId}
   	runtime.SetFinalizer(msgId, messageIdFinalizer)
   	return msgId
   }
   ```

##########
File path: pulsar-client-go/pulsar/c_producer.go
##########
@@ -298,6 +298,7 @@ func pulsarProducerSendCallbackProxyWithMsgID(res C.pulsar_result, messageId *C.
 		sendCallback.callback(getMessageId(messageId), newError(res, "Failed to send message"))
 	} else {
 		sendCallback.callback(getMessageId(messageId), nil)
+		C.pulsar_message_id_free(messageId)

Review comment:
       @bschofield I think this free should not be done, because `getMessageId(messageId)` is already attaching a finalizer to the Go object and it will free the message id automatically:
   
   ```go
   func getMessageId(messageId *C.pulsar_message_id_t) MessageID {
   	msgId := &messageID{ptr: messageId}
   	runtime.SetFinalizer(msgId, messageIdFinalizer)
   	return msgId
   }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org