Falldog / pyconcrete

Protect your python script, encrypt it as .pye and decrypt when import it
Apache License 2.0
702 stars 150 forks source link

Memory has been released #36

Closed zhaohainan666 closed 6 years ago

zhaohainan666 commented 6 years ago

https://github.com/Falldog/pyconcrete/blob/49352b2c3a725e48e53ac27a8f524b9d7af808f1/src/pyconcrete_exe/pyconcrete_exe.c#L142

py_content has been released in Py_DECREF(py_args)

SashaAVCO commented 6 years ago

Thank you. Looks like this bug related to https://github.com/Falldog/pyconcrete/issues/31 , so if additionally to described there changes I comment this line of code //Py_DECREF(py_args); , then I don't need anymore moving free(content) to the middle of the func from the end of code block where it was before. So looks like this double-free call sometimes destroyed something so next free(..) failed then.

zhaohainan666 commented 6 years ago

According to the Python documentation, PyTuple_SetItem steals a reference to the inserted object. So you shouldn't dereference py_content manually since py_args now owns py_content.

I think you should remove the Py_DECREF(py_content); line instead of the Py_DECREF(py_args); line.

SashaAVCO commented 6 years ago

Ok. Just posted the resulted source code (that works Ok for me at least now both for simple example and for complex project with many-many *.python modules):

https://github.com/Falldog/pyconcrete/issues/31

Falldog commented 6 years ago

@zhaohainan666 excellent, thanks for your help, I didn't notice the PyTuple_SetItem will steal a reference. I can't reproduce the issue. I will fix it and please help to check it in the latest code, thanks.