abdeladim-s / pywhispercpp

Python bindings for whisper.cpp
https://abdeladim-s.github.io/pywhispercpp/
MIT License
180 stars 26 forks source link

params.language is leaking memory and crashes if assigned with None #68

Closed PiotrCzapla closed 1 month ago

PiotrCzapla commented 1 month ago

The lib was crashing on my Mac with python 3.11, after checking why tit seems that the lines are problematic:

https://github.com/abdeladim-s/pywhispercpp/blob/6fdccd7a1d6ef758020e7c116fad511794777e58/src/main.cpp#L483C6-L485C123

I noticed that the sizeof is being used for memory allocation, which returns the size of the pointer rather than the length of the string itself. To get the actual string size we should use strlen.

Also, I see that malloc is used, but there’s no mechanism in place to free the memory afterwards, which could lead to memory leaks.

I’ll send you a PR in a sec to address these issues.