From 7c99ff2a00e56a8444cdbb05b06226dc81f899ed Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Thu, 2 Jun 2016 20:33:01 +0200 Subject: [PATCH] fix segfault when passing a docstring to def_property* (fixes #222) --- include/pybind11/pybind11.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 4ffe1108f..cfbb0f9a3 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -860,9 +860,20 @@ public: template class_ &def_property_static(const char *name, const cpp_function &fget, const cpp_function &fset, const Extra& ...extra) { auto rec_fget = get_function_record(fget), rec_fset = get_function_record(fset); + char *doc_prev = rec_fget->doc; /* 'extra' field may include a property-specific documentation string */ detail::process_attributes::init(extra..., rec_fget); - if (rec_fset) + if (rec_fget->doc && rec_fget->doc != doc_prev) { + free(doc_prev); + rec_fget->doc = strdup(rec_fget->doc); + } + if (rec_fset) { + doc_prev = rec_fset->doc; detail::process_attributes::init(extra..., rec_fset); + if (rec_fset->doc && rec_fset->doc != doc_prev) { + free(doc_prev); + rec_fset->doc = strdup(rec_fset->doc); + } + } pybind11::str doc_obj = pybind11::str(rec_fget->doc ? rec_fget->doc : ""); object property( PyObject_CallFunctionObjArgs((PyObject *) &PyProperty_Type, fget.ptr() ? fget.ptr() : Py_None,