rados/conn: Fix passing of Go allocated pointer to CGO function in MonCommand(), which panics Go 1.6.

Addresses issue #10.
This commit is contained in:
Livio Soares 2016-03-24 22:13:09 -04:00
parent 5133b0eaa2
commit 6f8cc46f47
1 changed files with 3 additions and 5 deletions

View File

@ -262,10 +262,8 @@ func (c *Conn) DeletePool(name string) error {
// MonCommand sends a command to one of the monitors
func (c *Conn) MonCommand(args []byte) (buffer []byte, info string, err error) {
argv := make([]*C.char, len(args))
for i, _ := range args {
argv[i] = (*C.char)(unsafe.Pointer(&args[i]))
}
argv := C.CString(string(args))
defer C.free(unsafe.Pointer(argv))
var (
outs, outbuf *C.char
@ -275,7 +273,7 @@ func (c *Conn) MonCommand(args []byte) (buffer []byte, info string, err error) {
defer C.free(unsafe.Pointer(inbuf))
ret := C.rados_mon_command(c.cluster,
&argv[0], C.size_t(len(args)),
&argv, 1,
inbuf, // bulk input (e.g. crush map)
C.size_t(0), // length inbuf
&outbuf, // buffer