diff --git a/librclone/README.md b/librclone/README.md index 5b9f7fe6d..56dbb7fc5 100644 --- a/librclone/README.md +++ b/librclone/README.md @@ -31,6 +31,7 @@ For documentation see the Go documentation for: - [RcloneInitialize](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneInitialize) - [RcloneFinalize](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneFinalize) - [RcloneRPC](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneRPC) +- [RcloneFreeString](https://pkg.go.dev/github.com/rclone/rclone/librclone#RcloneFreeString) ### C Example diff --git a/librclone/librclone.go b/librclone/librclone.go index 0ad94d301..90c22a04a 100644 --- a/librclone/librclone.go +++ b/librclone/librclone.go @@ -20,6 +20,8 @@ package main /* +#include + struct RcloneRPCResult { char* Output; int Status; @@ -28,6 +30,8 @@ struct RcloneRPCResult { import "C" import ( + "unsafe" + "github.com/rclone/rclone/librclone/librclone" _ "github.com/rclone/rclone/backend/all" // import all backends @@ -79,5 +83,17 @@ func RcloneRPC(method *C.char, input *C.char) (result C.struct_RcloneRPCResult) return result } +// RcloneFreeString may be used to free the string returned by RcloneRPC +// +// If the caller has access to the C standard library, the free function can +// normally be called directly instead. In some cases the caller uses a +// runtime library which is not compatible, and then this function can be +// used to release the memory with the same library that allocated it. +// +//export RcloneFreeString +func RcloneFreeString(str *C.char) { + C.free(unsafe.Pointer(str)) +} + // do nothing here - necessary for building into a C library func main() {}