Improve some freeing in the examples

This commit is contained in:
kdeme 2019-11-18 21:55:09 +01:00 committed by zah
parent d781a25f30
commit 187bd22cc2
2 changed files with 4 additions and 1 deletions

View File

@ -46,8 +46,8 @@ func Start() {
}
peer1 := C.CString("enode://2d3e27d7846564f9b964308038dfadd4076e4373ac938e020708ad8819fd4fd90e5eb8314140768f782db704cb313b60707b968f8b61108a6fecd705b041746d@192.168.0.33:30303")
defer C.free(unsafe.Pointer(peer1))
C.nimbus_add_peer(peer1)
C.free(unsafe.Pointer(peer1))
}
func StatusListenAndPost(channel string) {

View File

@ -62,6 +62,7 @@ func StatusListenAndPost(channel string) {
tmp := C.malloc(C.size_t(C.ID_LEN))
if C.nimbus_add_symkey_from_password(channelC, (*C.uint8_t)(tmp)) == false {
C.free(unsafe.Pointer(tmp))
panic("Cannot create symmetric key")
}
// No need to do this back and forth GO <-> C, just showing how it might work
@ -73,6 +74,7 @@ func StatusListenAndPost(channel string) {
tmp = C.malloc(C.size_t(C.ID_LEN))
if C.nimbus_new_keypair((*C.uint8_t)(tmp)) == false {
C.free(unsafe.Pointer(tmp))
panic("Cannot create asymmetric keypair")
}
// No need to do this back and forth GO <-> C, just showing how it might work
@ -92,6 +94,7 @@ func StatusListenAndPost(channel string) {
if C.nimbus_subscribe_filter(&options,
(C.received_msg_handler)(unsafe.Pointer(C.receiveHandler_cgo)),
unsafe.Pointer(&msgCount), (*C.uint8_t)(tmp)) == false {
C.free(unsafe.Pointer(tmp))
panic("Cannot subscribe filter")
}
filterId := C.GoBytes(tmp, C.ID_LEN)