[Haskell-cafe] Allocating a new ByteString

Tristan Seligmann mithrandi at mithrandi.net
Tue Dec 23 06:19:50 UTC 2014

On 23 December 2014 at 08:10, Yuras Shumovich <shumovichy at gmail.com> wrote:
> Looks like you need 'unsafePackCStringFinalizer' (or one of it's variants)
> from Data.ByteString.Unsafe module. It lets you reuse the buffer and
> deallocate it in finalizer. Something similar is used e.g. in 'kyotocabinet'
> package.

I tried using this, but it seems like the pointer created by
mallocForeignPtrBytes is freed as soon as it is no longer referenced
(upon returning from the function). Then, later, when the bytestring
is finalized, the pointer is freed again causing an abort on
double-free. How do I "transfer" ownership of the pointer?
mithrandi, i Ainil en-Balandor, a faer Ambar

More information about the Haskell-Cafe mailing list