Coder Social home page Coder Social logo

Comments (8)

plusvic avatar plusvic commented on May 11, 2024

This fix seems to work, but I'm not familiarized yet withcgo.

With that fixgo vet says: possible misuse of unsafe.Pointer because of the conversion of anuintptr back tounsafe.Pointer, but in this case I would say that's perfectly safe. The conversion is necessary only because yr_compiler_set_callback expects a void* for user_data and cgo translates it into unsafe.Pointer.

from go-yara.

hillu avatar hillu commented on May 11, 2024

I have been able to reproduce the issue with Go 1.8.5 but not with Go 1.9.2 (Debian unstable/amd64). What version are you using?

My belief is that the garbage collector collects id right after it has been passed to C.compiler_set_callback.. Adding keepalive(id) at the end of the function seems to fix the issue here.

from go-yara.

plusvic avatar plusvic commented on May 11, 2024

I have Go 1.8 too.

Your belief makes sense. At first I thought that too, but then read that the GC doesn't free the object if you hold an unsafe.Pointer to it, and discarded the idea. What I didn't noticed is that the pointer is not hold by the function neither, so nothing prevents the GC from freeing id.

from go-yara.

plusvic avatar plusvic commented on May 11, 2024

BTW, what do you think about plusvic@7275017, I believe it's safe even if go vet complains, but I would like to hear a second opinion. I like it because you don't need to pass the address of id to the callback, you can pass id itself.

from go-yara.

hillu avatar hillu commented on May 11, 2024

I have gone through a few iterations of trying to use integers / uintptr values where the Go compiler and/or runtime thought it was passing pointers around. It would work with the then-current compiler/runtime version but then the CGO rules (which are underdocumented anyway) would get changed and things would break.

At this point I have pretty much given up on that idea. Let's see if explicitly keeping the id values alive will do the trick...

from go-yara.

hillu avatar hillu commented on May 11, 2024

Let's see what the Travis CI setup comes up with...

from go-yara.

hillu avatar hillu commented on May 11, 2024

Woohoo, it crashed with every Go version but tip.

from go-yara.

hillu avatar hillu commented on May 11, 2024

Ah well, it seems like the keepAlive function for go 1.6 also has a beneficial effect in this case. I am getting too old for this nonsense.

from go-yara.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.