Use the Type() ctor and avoid:

- clang warning about memset overwrite of vtable
  - memory leak
  - Undefined behavior in Type copy/move operations and dtor.
This commit is contained in:
Mike Romberg 2017-07-01 17:58:59 -06:00
commit 6c0885ff67

View file

@ -134,13 +134,12 @@ namespace swig {
return *v; return *v;
} }
} else { } else {
// Uninitialized return value, no Type() constructor required. static Type v_def;
static Type *v_def = (Type*) calloc(1, sizeof(Type)); // memory leak?
if (!PyErr_Occurred()) { if (!PyErr_Occurred()) {
%type_error(swig::type_name<Type>()); %type_error(swig::type_name<Type>());
} }
if (throw_error) throw std::invalid_argument("bad type"); if (throw_error) throw std::invalid_argument("bad type");
return *v_def; return v_def;
} }
} }
}; };