[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[HTCondor-users] Segfault by the ClassAd python-wrapper

Package: htcondor-python-binding

Version: 8.7.8

Severity: normal




I encountered a bug with the python-bindings of ClassAd objects. Below are the minimal codes to reproduce the problem:


       Python 3.6.5 | packaged by conda-forge | (default, Apr  6 2018, 13:39:56)

       [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)] on linux

       >>> import htcondor, classad

       >>> coll  = htcondor.Collector()

       >>> schedd= htcondor.Schedd(coll.locate(htcondor.DaemonTypes.Schedd))

       >>> print([(k,v) for k,v in schedd.query()[0].items()])


       Segmentation fault (core dumped)


The root of this SEGFAULT is that the `items` method of `ClassAdWrapper` returns invalid references to its child objects. A ClassAd object usually contains some objects of nontrivial type, such as `classad.ExprTree`, which are destroyed when their parent is garbage-collected by the python runtime. Therefore trying to access such objects results in memory access violation (SEGFAULT). Here is the code section responsible for it: https://github.com/htcondor/htcondor/blob/3c73f7c8bcb9d4b99793cd3bc97251639e18b99d/src/python-bindings/classad.cpp#L993


This is a python3-only problem because the `items` method of python 3 object returns an `iterator` instead of a list of tuples.


The proposed solution is to properly transform any non-trivial child object of `ClassAdWrapper` into a python object (with its own reference counter) so that the runtime can garbage collected them correctly.



Mingxuan Lin