diff --git a/src/main/conversions.c b/src/main/conversions.c index b9e446c5c4..4da1a75f18 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -1308,10 +1308,14 @@ as_status as_val_new_from_pyobject(AerospikeClient *self, as_error *err, Py_DECREF(py_parameter); PyObject *geospatial_dump = AerospikeGeospatial_DoDumps(py_data, err); + Py_XDECREF(py_data); + if (!geospatial_dump) { + return as_error_update(err, AEROSPIKE_ERR_CLIENT, + "Unable to call dumps function"); + } const char *geo_value = PyUnicode_AsUTF8(geospatial_dump); char *geo_value_cpy = strdup(geo_value); - Py_DECREF(py_data); Py_DECREF(geospatial_dump); *val = (as_val *)as_geojson_new(geo_value_cpy, true); @@ -2231,6 +2235,12 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, else if (!strcmp(py_value->ob_type->tp_name, "aerospike.Geospatial")) { PyObject *geo_data = PyObject_GetAttrString(py_value, "geo_data"); PyObject *geo_data_py_str = AerospikeGeospatial_DoDumps(geo_data, err); + Py_XDECREF(geo_data); + if (!geo_data_py_str) { + as_error_update(err, AEROSPIKE_ERR_CLIENT, + "Unable to call dumps function"); + return; + } const char *geo_data_str = PyUnicode_AsUTF8(geo_data_py_str); // Make a copy of the encoding since the utf8 encoding points to a buffer in the PyUnicode object @@ -2243,7 +2253,6 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, // Cleanup Py_XDECREF(geo_data_py_str); - Py_XDECREF(geo_data); } else if (!strcmp(py_value->ob_type->tp_name, "aerospike.null")) { ((as_val *)&binop_bin->value)->type = AS_UNKNOWN; diff --git a/src/main/convert_expressions.c b/src/main/convert_expressions.c index c077443b53..9ab0a8ade7 100644 --- a/src/main/convert_expressions.c +++ b/src/main/convert_expressions.c @@ -513,9 +513,14 @@ get_exp_val_from_pyval(AerospikeClient *self, as_static_pool *static_pool, PyObject *py_parameter = PyUnicode_FromString("geo_data"); PyObject *py_data = PyObject_GenericGetAttr(py_obj, py_parameter); Py_DECREF(py_parameter); - char *geo_value = - (char *)PyUnicode_AsUTF8(AerospikeGeospatial_DoDumps(py_data, err)); - Py_DECREF(py_data); + PyObject *geospatial_dump = AerospikeGeospatial_DoDumps(py_data, err); + Py_XDECREF(py_data); + if (!geospatial_dump) { + return as_error_update(err, AEROSPIKE_ERR_CLIENT, + "Unable to call dumps function"); + } + char *geo_value = (char *)PyUnicode_AsUTF8(geospatial_dump); + as_exp_entry tmp_entry = as_exp_geo(geo_value); *new_entry = tmp_entry; } diff --git a/src/main/geospatial/dumps.c b/src/main/geospatial/dumps.c index e0a9f1bb5f..412fc46407 100644 --- a/src/main/geospatial/dumps.c +++ b/src/main/geospatial/dumps.c @@ -39,12 +39,7 @@ PyObject *AerospikeGeospatial_DoDumps(PyObject *geo_data, as_error *err) json_module = PyImport_ImportModule("json"); } - if (!json_module) { - /* insert error handling here! and exit this function */ - as_error_update(err, AEROSPIKE_ERR_CLIENT, - "Unable to load json module"); - } - else { + if (json_module && geo_data) { PyObject *py_funcname = PyUnicode_FromString("dumps"); initresult = PyObject_CallMethodObjArgs(json_module, py_funcname, geo_data, NULL); diff --git a/src/main/predicates.c b/src/main/predicates.c index b386c2aefe..5e41960f14 100644 --- a/src/main/predicates.c +++ b/src/main/predicates.c @@ -236,7 +236,6 @@ static PyObject *AerospikePredicates_GeoWithin_Radius(PyObject *self, "double type, bin of string type"); goto CLEANUP; } - Py_CLEAR(py_geo_object); ret_val = Py_BuildValue("iiOOOO", AS_PREDICATE_RANGE, AS_INDEX_GEO2DSPHERE, py_bin, py_shape, Py_None, py_indexType); @@ -319,10 +318,8 @@ static PyObject *AerospikePredicates_GeoContains_Point(PyObject *self, py_list = Py_BuildValue("[OO]", py_lat, py_long); PyDict_SetItemString(py_geo_object, "coordinates", py_list); - Py_CLEAR(py_list); py_shape = AerospikeGeospatial_DoDumps(py_geo_object, &err); - Py_CLEAR(py_geo_object); if (!py_shape) { as_error_update(&err, AEROSPIKE_ERR_CLIENT,