On Fri, Aug 18, 2017 at 12:53 AM, Bhaskar Singhal
<[email protected]> wrote:
> I am running into a seg fault. The code keeps crashing either due to
> unexpected signal or double free.
>
> Any pointers on what I am doing wrong here:
>
> Code Snippet:
> // Put puts the given key / value to the kvstore
> func (kvs *kvstore) Put(key []byte, value []byte) error {
>         /* Encode key to avoid null characters in byte[] */
>         strk := base64.StdEncoding.EncodeToString([]byte(key))
>         csk := C.CString(strk)
>         defer C.free(unsafe.Pointer(csk))
>
>         /* Encode value to avoid null characters in byte[] */
>         strv := base64.StdEncoding.EncodeToString([]byte(value))
>         csv := C.CString(strv)
>         defer C.free(unsafe.Pointer(csv))
>
>         if kvs.kvtree == nil {
>                 return fmt.Errorf("put failed because kvtree is nil")
>         }
>         size := C.int32_t(len(strv))
>
>         ret := C.put(kvs.kvtree, csk, csv, &size)
>         if ret != C.int8_t(1) {
>                 return fmt.Errorf("kvtree put failed %g", ret)
>         }
>         return nil
> }
>
> C Function Put:
> int8_t put(KVTree* kv,
>                   const char* key,
>                   const char* value,
>                   const int32_t* valuebytes);


It really depends on how the C function behaves.  My guess is that it
does not expect the values to be freed.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to