Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retreiving valid PyEnvironment from PyAbstract1 #2

Closed
pascalito opened this issue Jun 9, 2020 · 2 comments
Closed

Retreiving valid PyEnvironment from PyAbstract1 #2

pascalito opened this issue Jun 9, 2020 · 2 comments

Comments

@pascalito
Copy link

Hello Caterina,

The environment property of the PyAbstract1 objects causes my Python program to crash with a segmentation fault (and even my Python debugger when inspecting such objects).

Here is a minimalist version that should go wrong on any computer:

import gc

from apronpy.var import PyVar
from apronpy.environment import PyEnvironment
from apronpy.box import PyBoxMPQManager
from apronpy.abstract1 import PyAbstract1

env = PyEnvironment([PyVar('x')])
man = PyBoxMPQManager()
abs_value = PyAbstract1.top(man, env)

inner_env_A = abs_value.environment
inner_env_B = abs_value.environment
inner_env_C = abs_value.environment

del inner_env_A
del inner_env_B
del inner_env_C  # Fails with SIGSEGV or double free or invalid pointer

gc.collect()  # Just to be sure that __del__ was called

Is it a bug ?

Note that this program does not use the APRON ctypes directly but uses only their Python proxies (Py*). In my humble opinion, this should not end with a segmentation fault.

Fix suggestion

I guess that this problem is triggered by the code of the environment property of the PyAbstract1 class. This code builds a PyEnvironment without increment of the APRON environment reference counter but eventually triggers a decrement through the __del__ method of the newly created PyEnvironment.

Adding the increment in the PyEnvironment constructor or in the environment property fixes this issue. I would not swear that these fixes are sound and memory-leak free...

Improvement suggestion

In passing, it would be nice that the Py*1 classes could all offer a way of retrieving the underlying environment as a PyEnvironment object.

@caterinaurban
Copy link
Owner

Thanks, good catch! I will implement your improvement suggestion as soon as I have a moment. It's delicate to do, to avoid memory leaks or segmentation faults.

@pascalito
Copy link
Author

The fix works fine. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants