Export to GitHub

word2vec - issue #2

Patch for word2vec.c: Fix memory leaks


Posted on Aug 17, 2013 by Helpful Dog

word2vec does not free allocated objects correctly. It also reads freed objects. Attached patch fixes this issue.

Attachments

Comment #1

Posted on Aug 17, 2013 by Happy Elephant

FYI I had to roll back this patch because when using demo-word.sh it was producing a vector.bin file that was unreadable by the distance utility.

Possibly related (but I doubt it): this was after also changing include headers for Mac OS X compilation (see https://github.com/dav/word2vec/commit/94bc3d7860670053d4785a5aa07737235ae4e272)

btw, I think you meant DestroyVocab not DestoryVocab

Comment #2

Posted on Aug 17, 2013 by Helpful Dog

Thanks dav.yagi...@gmail.com for comments and typos. The fixed patch attached.

There was a bug in SortVocab in which the special word "" was freed. On Ubuntu 12.04.2, demo-word.sh works fine. I think it works fine on OS X as well.

I checked your commits on the github repository, and I think the changes are not relate to this issue. It is related to compilation issues on OS X because of missing header "malloc.h".

Attachments

Comment #3

Posted on Aug 18, 2013 by Happy Elephant

New patch seems to work fine, thanks.

Comment #4

Posted on Aug 23, 2013 by Grumpy Ox

Where is it reading a freed memory? The added error messages assume the error, e.g. no such file or directory. Is it worth the bother of freeing a lot of this memory when the OS will do it much more efficiently when the program exits soon after?

Status: New

Labels:
Type-Defect Priority-Medium