V9.5 Go SDK: pointer being freed was not allocated


I’ve been using v9.4 of the Go SDK for some PDF processing, but I’ve run into an issue when I attempt to upgrade to v9.5.

Using this code and the attached sample document with v9.4, the little application will finish successfully and print the message Found match: "Hello!".

package main

import (


func main() {
	// Initialize PDFTron
	licenseKey := os.Getenv("PDFTRON_LICENSE_KEY")

	// Load sample document
	content, err := ioutil.ReadFile("sample.pdf")
	if err != nil {
		msg := fmt.Sprintf("error while opening sample.pdf: %v", err)

	// Start the workload
	doc := pdftron.NewPDFDoc(&content[0], int64(len(content)))

	txtSearch := pdftron.NewTextSearch()
	defer txtSearch.Destroy()

	mode := pdftron.TextSearchE_highlight | pdftron.TextSearchE_reg_expression
	if ok := txtSearch.Begin(doc, "Hello.*", uint(mode)); !ok {
		panic("failed to initialize text search")

	searchResults := txtSearch.Run()
	if !searchResults.IsFound() {
		panic("no results found")

	highlights := searchResults.GetHighlights()

	txtRange := highlights.GetCurrentTextRange()
	textMatch := txtRange.GetText()

	fmt.Printf("Found match: %q\n", textMatch)

After upgrading to v9.5, I get the following error message when I try to run the same code. Is this a bug or has the way to call the code changed?

PDFNet is running in demo mode.
Package: base
sandbox(40027,0x7ff85bbc3680) malloc: *** error for object 0x7ff7bfefe8d0: pointer being freed was not allocated
sandbox(40027,0x7ff85bbc3680) malloc: *** set a breakpoint in malloc_error_break to debug
SIGABRT: abort
PC=0x7ff81824e22a m=0 sigcode=0
signal arrived during cgo execution

goroutine 1 [syscall]:
runtime.cgocall(0x1000e62a0, 0xc000073e58)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc000073e30 sp=0xc000073df8 pc=0x10000335c
        _cgo_gotypes.go:28218 +0x4d fp=0xc000073e58 sp=0xc000073e30 pc=0x10009124d
        <autogenerated>:1 +0x31 fp=0xc000073e78 sp=0xc000073e58 pc=0x1000cdeb1
        /Users/username/Sandbox/repo/cmd/sandbox/main.go:43 +0x2d5 fp=0xc000073f80 sp=0xc000073e78 pc=0x1000ce815
        /usr/local/go/src/runtime/proc.go:250 +0x207 fp=0xc000073fe0 sp=0xc000073f80 pc=0x1000336c7
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000073fe8 sp=0xc000073fe0 pc=0x10005e741

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000060fb0 sp=0xc000060f90 pc=0x100033af6
        /usr/local/go/src/runtime/proc.go:305 +0xb0 fp=0xc000060fe0 sp=0xc000060fb0 pc=0x100033930
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000060fe8 sp=0xc000060fe0 pc=0x10005e741
created by runtime.init.6
        /usr/local/go/src/runtime/proc.go:293 +0x25

goroutine 3 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000061780 sp=0xc000061760 pc=0x100033af6
        /usr/local/go/src/runtime/mgcsweep.go:278 +0x8e fp=0xc0000617c8 sp=0xc000061780 pc=0x1000211ae
        /usr/local/go/src/runtime/mgc.go:178 +0x26 fp=0xc0000617e0 sp=0xc0000617c8 pc=0x100016646
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000617e8 sp=0xc0000617e0 pc=0x10005e741
created by runtime.gcenable
        /usr/local/go/src/runtime/mgc.go:178 +0x6b

goroutine 4 [GC scavenge wait]:
runtime.gopark(0xc0000241c0?, 0x10019e370?, 0x1?, 0x0?, 0x0?)
        /usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000061f70 sp=0xc000061f50 pc=0x100033af6
        /usr/local/go/src/runtime/mgcscavenge.go:400 +0x53 fp=0xc000061fa0 sp=0xc000061f70 pc=0x10001f0b3
        /usr/local/go/src/runtime/mgcscavenge.go:628 +0x45 fp=0xc000061fc8 sp=0xc000061fa0 pc=0x10001f685
        /usr/local/go/src/runtime/mgc.go:179 +0x26 fp=0xc000061fe0 sp=0xc000061fc8 pc=0x1000165e6
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000061fe8 sp=0xc000061fe0 pc=0x10005e741
created by runtime.gcenable
        /usr/local/go/src/runtime/mgc.go:179 +0xaa

goroutine 5 [finalizer wait]:
runtime.gopark(0x1a0?, 0x1002af580?, 0x60?, 0x78?, 0xc000060770?)
        /usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000060628 sp=0xc000060608 pc=0x100033af6
        /usr/local/go/src/runtime/mfinal.go:193 +0x107 fp=0xc0000607e0 sp=0xc000060628 pc=0x100015687
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc0000607e8 sp=0xc0000607e0 pc=0x10005e741
created by runtime.createfing
        /usr/local/go/src/runtime/mfinal.go:163 +0x45

rax    0x0
rbx    0x7ff85bbc3680
rcx    0x7ff7bfefdfe8
rdx    0x0
rdi    0x103
rsi    0x6
rbp    0x7ff7bfefe010
rsp    0x7ff7bfefdfe8
r8     0x1
r9     0x0
r10    0x0
r11    0x246
r12    0x103
r13    0x1006df028
r14    0x6
r15    0x16
rip    0x7ff81824e22a
rflags 0x246
cs     0x7
fs     0x0
gs     0x0
exit status 2

Thanks in advanced,

sample.pdf (13.4 KB)

Is the issue particular to this one PDF file?
Or can you reproduce with any PDF file?
Does the issue occur every time? If not, how often?
Can you reproduce on a different machine?

Hello @Ryan,

Thanks for taking a look at the issue.

  • The issue occurs for any document that I’ve tried
  • It occurs every time
  • It isn’t machine-dependant. It fails on my MBP and an Ubuntu server

Is it possible it’ll be addressed by this PR: Update for 9.5.0 hotfix. by rchennafi · Pull Request #8 · PDFTron/pdftron-go · GitHub


I don’t believe so no, that appears to be for unrelated API’s.

The team does believe they have reproduced the issue and are investigating. I will update you once I know more.

Excellent, thanks for the update Ryan!

If I can provide anything else, just let me know.


Hello Ryan,

Is there an update on this item?


Nothing specific yet, but I know the team is actively working on updating the Go package. There is a new PDFNet 10.0 release possibly coming as early as next week, so perhaps around then.

Hi Ben,

As Ryan mentioned the 10.0 release will include the new Go library as well. The new go library will not have any of the manual steps our previous did, and will simply be imported & used rather than created via a new import.

That being said, how did you upgrade to 9.5 with Go? Our own package via pkg.go.dev has actually not been updated in some time and was not properly updated to 9.5 either.

Thank you to both of you for your responses. I’ll keep my eye out for the 10.0 release!

To answer @Ramzi_Chennafi’s question, I’m subscribed to receive notifications when new releases are created in the pdftron-go repository. I download the latest release from there and update our project.

Having the ability to use a standard Go import will be great!


I upgraded to v10.0 today. I can confirm that it resolves this issue.

Thank you to everyone who helped with it!