Comments (8)
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.
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.
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.
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.
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.
Let's see what the Travis CI setup comes up with...
from go-yara.
Woohoo, it crashed with every Go version but tip.
from go-yara.
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)
- Issues while installing HOT 7
- Unable to use ScanProc HOT 23
- Unable to define variable on AIX HOT 4
- Scan a file in a streaming maner HOT 2
- Encrypted rules? HOT 4
- unstable rules HOT 5
- Wrong release version? HOT 1
- Building static binary HOT 3
- cannot find -lyara HOT 1
- linux编译yara出现错误 HOT 2
- generate a dynamic-link library (.so file) HOT 1
- v3.x no release tag HOT 1
- Failing to compile with go-yara HOT 9
- yararule.ScanFile, can not scan filepath which contains chinese, may be other language has the same HOT 2
- Attempt to add a new YARA rule files during runtime causes panic HOT 1
- Question: Adding multiple Compiled YARA files to a single yara.Scanner or *yara.Rules HOT 1
- building simple example on linux fails HOT 2
- simple-yara failed to run HOT 4
- SIGSEGV: segmentation violation on .ScanMem HOT 4
- ScanFile() increased memory by 300MB after scanning a large file and did not release HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-yara.