@@ -62,10 +62,12 @@ func makeMemoryBlockIteratorContainer(mbi MemoryBlockIterator) (c *memoryBlockIt
62
62
return
63
63
}
64
64
65
- // The caller is responsible to delete the cgoHandle cmbi.context.
65
+ // The caller is responsible to delete the cgoHandle *cmbi.context and free cmbi.context.
66
66
func makeCMemoryBlockIterator (c * memoryBlockIteratorContainer ) (cmbi * C.YR_MEMORY_BLOCK_ITERATOR ) {
67
+ userData := (* cgoHandle )(C .malloc (C .size_t (unsafe .Sizeof (cgoHandle (0 )))))
68
+ * userData = cgoNewHandle (c )
67
69
cmbi = & C.YR_MEMORY_BLOCK_ITERATOR {
68
- context : unsafe .Pointer (cgoNewHandle ( c ) ),
70
+ context : unsafe .Pointer (userData ),
69
71
first : C .YR_MEMORY_BLOCK_ITERATOR_FUNC (C .memoryBlockIteratorFirst ),
70
72
next : C .YR_MEMORY_BLOCK_ITERATOR_FUNC (C .memoryBlockIteratorNext ),
71
73
}
@@ -108,7 +110,7 @@ type MemoryBlock struct {
108
110
//
109
111
//export memoryBlockFetch
110
112
func memoryBlockFetch (cblock * C.YR_MEMORY_BLOCK ) * C.uint8_t {
111
- c := cgoHandle (cblock .context ).Value ().(* memoryBlockIteratorContainer )
113
+ c := (( * cgoHandle ) (cblock .context ) ).Value ().(* memoryBlockIteratorContainer )
112
114
c .realloc (int (cblock .size ))
113
115
c .MemoryBlock .FetchData (c .buf )
114
116
return (* C .uint8_t )(unsafe .Pointer (& c .buf [0 ]))
@@ -143,7 +145,7 @@ func memoryBlockIteratorCommon(cmbi *C.YR_MEMORY_BLOCK_ITERATOR, c *memoryBlockI
143
145
//
144
146
//export memoryBlockIteratorFirst
145
147
func memoryBlockIteratorFirst (cmbi * C.YR_MEMORY_BLOCK_ITERATOR ) * C.YR_MEMORY_BLOCK {
146
- c := cgoHandle (cmbi .context ).Value ().(* memoryBlockIteratorContainer )
148
+ c := (( * cgoHandle ) (cmbi .context ) ).Value ().(* memoryBlockIteratorContainer )
147
149
c .MemoryBlock = c .MemoryBlockIterator .First ()
148
150
return memoryBlockIteratorCommon (cmbi , c )
149
151
}
@@ -153,13 +155,13 @@ func memoryBlockIteratorFirst(cmbi *C.YR_MEMORY_BLOCK_ITERATOR) *C.YR_MEMORY_BLO
153
155
//
154
156
//export memoryBlockIteratorNext
155
157
func memoryBlockIteratorNext (cmbi * C.YR_MEMORY_BLOCK_ITERATOR ) * C.YR_MEMORY_BLOCK {
156
- c := cgoHandle (cmbi .context ).Value ().(* memoryBlockIteratorContainer )
158
+ c := (( * cgoHandle ) (cmbi .context ) ).Value ().(* memoryBlockIteratorContainer )
157
159
c .MemoryBlock = c .MemoryBlockIterator .Next ()
158
160
return memoryBlockIteratorCommon (cmbi , c )
159
161
}
160
162
161
163
//export memoryBlockIteratorFilesize
162
164
func memoryBlockIteratorFilesize (cmbi * C.YR_MEMORY_BLOCK_ITERATOR ) C.uint64_t {
163
- c := cgoHandle (cmbi .context ).Value ().(* memoryBlockIteratorContainer )
165
+ c := (( * cgoHandle ) (cmbi .context ) ).Value ().(* memoryBlockIteratorContainer )
164
166
return C .uint64_t (c .MemoryBlockIterator .(MemoryBlockIteratorWithFilesize ).Filesize ())
165
167
}
0 commit comments