MonetDB: default - fixing leaks

2021-11-10 Thread Niels Nes
Changeset: de1cbb7275ca for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/de1cbb7275ca
Modified Files:
monetdb5/optimizer/opt_dict.c
monetdb5/optimizer/opt_for.c
sql/backends/monet5/for.c
sql/storage/store.c
Branch: default
Log Message:

fixing leaks


diffs (202 lines):

diff --git a/monetdb5/optimizer/opt_dict.c b/monetdb5/optimizer/opt_dict.c
--- a/monetdb5/optimizer/opt_dict.c
+++ b/monetdb5/optimizer/opt_dict.c
@@ -71,6 +71,7 @@ OPTdictImplementation(Client cntxt, MalB
varisdict[k] = getArg(p,1);
vardictvalue[k] = getArg(p, 2);
dictunique[k] = 1;
+   freeInstruction(p);
continue;
}
int done = 0;
@@ -90,6 +91,7 @@ OPTdictImplementation(Client cntxt, MalB
vardictvalue[l] = vardictvalue[k];
dictunique[l] = dictunique[k];
pushInstruction(mb,r);
+   freeInstruction(p);
done = 1;
break;
} else if (p->argc == 2 && p->retc == 1 && 
getFunctionId(p) == NULL) {
@@ -98,6 +100,7 @@ OPTdictImplementation(Client cntxt, MalB
varisdict[l] = varisdict[k];
vardictvalue[l] = vardictvalue[k];
dictunique[l] = dictunique[k];
+   freeInstruction(p);
done = 1;
break;
} else if (getModuleId(p) == algebraRef && 
getFunctionId(p) == subsliceRef) {
@@ -106,6 +109,7 @@ OPTdictImplementation(Client cntxt, MalB
InstrPtr r = copyInstruction(p);
getArg(r, j) = varisdict[k];
pushInstruction(mb,r);
+   freeInstruction(p);
done = 1;
break;
} else if (getModuleId(p) == batRef && 
getFunctionId(p) == mirrorRef) {
@@ -114,6 +118,7 @@ OPTdictImplementation(Client cntxt, MalB
InstrPtr r = copyInstruction(p);
getArg(r, j) = varisdict[k];
pushInstruction(mb,r);
+   freeInstruction(p);
done = 1;
break;
} else if (isSelect(p)) {
@@ -173,6 +178,7 @@ OPTdictImplementation(Client cntxt, MalB
t = pushNil(mb, t, TYPE_lng); 
/* estimate */
pushInstruction(mb,t);
}
+   freeInstruction(p);
done = 1;
break;
} else if (j == 2 && p->argc > j+1 && 
getModuleId(p) == algebraRef && getFunctionId(p) == joinRef
@@ -186,6 +192,7 @@ OPTdictImplementation(Client cntxt, MalB
getArg(r, j+0) = varisdict[k];
getArg(r, j+1) = varisdict[l];
pushInstruction(mb,r);
+   freeInstruction(p);
done = 1;
break;
} else if (j == 2 && p->argc > j+1 && 
getModuleId(p) == algebraRef && getFunctionId(p) == joinRef
@@ -207,6 +214,7 @@ OPTdictImplementation(Client cntxt, MalB
r = addArgument(mb, r, getArg(p, 6));
r = addArgument(mb, r, getArg(p, 7));
pushInstruction(mb,r);
+   freeInstruction(p);
done = 1;
break;
} else if ((isMapOp(p) || isMap2Op(p)) && 
allConstExcept(mb, p, j)) {
@@ -224,6 +232,7 @@ OPTdictImplementation(Client cntxt, MalB
vardictvalue[l] = vardictvalue[m] = 
getArg(r,0);
dictunique[l] = 0;
pushInstruction(mb,r);
+   freeInstruction(p);
done = 1;
break;
} else if (g

MonetDB: default - fixing leaks in the python sieve

2023-06-06 Thread Niels Nes via checkin-list
Changeset: 73fa640cdf6a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/73fa640cdf6a
Modified Files:
sql/backends/monet5/UDF/pyapi3/connection3.c
sql/backends/monet5/UDF/pyapi3/conversion3.c
sql/backends/monet5/UDF/pyapi3/convert_loops.h
sql/backends/monet5/UDF/pyapi3/pyapi3.c
Branch: default
Log Message:

fixing leaks in the python sieve


diffs (truncated from 401 to 300 lines):

diff --git a/sql/backends/monet5/UDF/pyapi3/connection3.c 
b/sql/backends/monet5/UDF/pyapi3/connection3.c
--- a/sql/backends/monet5/UDF/pyapi3/connection3.c
+++ b/sql/backends/monet5/UDF/pyapi3/connection3.c
@@ -15,7 +15,8 @@
 #include "type_conversion.h"
 #include "gdk_interprocess.h"
 
-static PyObject *_connection_execute(Py_ConnectionObject *self, PyObject *args)
+static PyObject *
+_connection_execute(Py_ConnectionObject *self, PyObject *args)
 {
char *query = NULL;
if (PyUnicode_CheckExact(args)) {
@@ -67,8 +68,7 @@ static PyObject *_connection_execute(Py_
input.scalar = false;
input.sql_subtype = &col.type;
 
-   numpy_array =
-   PyMaskedArray_FromBAT(&input, 0, 
input.count, &res, true);
+   numpy_array = PyMaskedArray_FromBAT(&input, 0, 
input.count, &res, true);
if (!numpy_array) {
_connection_cleanup_result(output);
BBPunfix(b->batCacheid);
@@ -76,9 +76,9 @@ static PyObject *_connection_execute(Py_
 (res ? 
getExceptionMessage(res) : ""));
return NULL;
}
-   PyDict_SetItem(result,
-  
PyUnicode_FromString(output->cols[i].name),
-  numpy_array);
+   PyObject *nme = 
PyUnicode_FromString(output->cols[i].name);
+   PyDict_SetItem(result, nme, numpy_array);
+   Py_DECREF(nme);
Py_DECREF(numpy_array);
BBPunfix(input.bat->batCacheid);
}
diff --git a/sql/backends/monet5/UDF/pyapi3/conversion3.c 
b/sql/backends/monet5/UDF/pyapi3/conversion3.c
--- a/sql/backends/monet5/UDF/pyapi3/conversion3.c
+++ b/sql/backends/monet5/UDF/pyapi3/conversion3.c
@@ -114,14 +114,13 @@ wrapup:
return vararray;
 }
 
-PyObject *PyMaskedArray_FromBAT(PyInput *inp, size_t t_start, size_t t_end,
-   char 
**return_message, bool copy)
+PyObject *
+PyMaskedArray_FromBAT(PyInput *inp, size_t t_start, size_t t_end, char 
**return_message, bool copy)
 {
BAT *b;
char *msg;
-   PyObject *vararray;
+   PyObject *vararray = PyArrayObject_FromBAT(inp, t_start, t_end, 
return_message, copy);
 
-   vararray = PyArrayObject_FromBAT(inp, t_start, t_end, return_message, 
copy);
if (vararray == NULL) {
return NULL;
}
@@ -137,12 +136,15 @@ PyObject *PyMaskedArray_FromBAT(PyInput 
bool bnonil = b->tnonil;
MT_lock_unset(&b->theaplock);
if (!bnonil) {
-   PyObject *mask;
-   PyObject *mafunc = PyObject_GetAttrString(
-   PyImport_Import(PyUnicode_FromString("numpy.ma")), 
"masked_array");
+   PyObject *nme = PyUnicode_FromString("numpy.ma");
+   PyObject *mod = PyImport_Import(nme);
+   PyObject *mafunc = PyObject_GetAttrString( mod, "masked_array");
PyObject *nullmask = PyNullMask_FromBAT(b, t_start, t_end);
+   Py_DECREF(nme);
 
if (!nullmask) {
+   Py_DECREF(mafunc);
+   Py_DECREF(mod);
msg = createException(MAL, "pyapi3.eval", "Failed to 
create mask for some reason");
goto wrapup;
} else if (nullmask == Py_None) {
@@ -154,16 +156,18 @@ PyObject *PyMaskedArray_FromBAT(PyInput 
 
// Now we will actually construct the mask by calling 
the masked
// array constructor
-   mask = PyObject_CallObject(mafunc, maargs);
+   PyObject *mask = PyObject_CallObject(mafunc, maargs);
+   Py_DECREF(maargs);
if (!mask) {
+   Py_DECREF(mafunc);
+   Py_DECREF(mod);
msg = createException(MAL, "pyapi3.eval", 
SQLSTATE(PY000) "Failed to create mask");
goto wrapup;
}
-