Skip to content

Commit

Permalink
Fixed memory leaks (#160)
Browse files Browse the repository at this point in the history
Fixed two memory leaks ( #159 )
  • Loading branch information
Zuzu-Typ authored Oct 30, 2021
1 parent 568bcb1 commit fbc82c8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
35 changes: 28 additions & 7 deletions PyGLM/internal_functions/number_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ double PyGLM_Number_AsDouble(PyObject* arg) {
return (arg == Py_True) ? 1.0 : 0.0;
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsDouble(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
double d = PyGLM_Number_AsDouble(num);
Py_DECREF(num);
return d;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return -1.0;
Expand All @@ -59,7 +62,10 @@ long PyGLM_Number_AsLong(PyObject* arg) {
return (arg == Py_True) ? 1 : 0;
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsLong(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
long l = PyGLM_Number_AsLong(num);
Py_DECREF(num);
return l;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return -1l;
Expand All @@ -82,7 +88,10 @@ unsigned long PyGLM_Number_AsUnsignedLong(PyObject* arg) {
return (arg == Py_True) ? 1UL : 0UL;
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsUnsignedLong(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
unsigned long l = PyGLM_Number_AsUnsignedLong(num);
Py_DECREF(num);
return l;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return (unsigned long) - 1l;
Expand All @@ -99,7 +108,10 @@ long long PyGLM_Number_AsLongLong(PyObject* arg) {
return (arg == Py_True) ? 1LL : 0LL;
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsLongLong(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
long long l = PyGLM_Number_AsLongLong(num);
Py_DECREF(num);
return l;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return -1ll;
Expand All @@ -122,7 +134,10 @@ unsigned long long PyGLM_Number_AsUnsignedLongLong(PyObject* arg) {
return (arg == Py_True) ? 1ull : 0ull;
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsUnsignedLongLong(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
unsigned long long l = PyGLM_Number_AsUnsignedLongLong(num);
Py_DECREF(num);
return l;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return (unsigned long long)-1ll;
Expand All @@ -139,7 +154,10 @@ bool PyGLM_Number_AsBool(PyObject* arg) {
return (bool)PyFloat_AS_DOUBLE(arg);
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsBool(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
bool b = PyGLM_Number_AsBool(num);
Py_DECREF(num);
return b;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return false;
Expand All @@ -156,7 +174,10 @@ float PyGLM_Number_AsFloat(PyObject* arg) {
return (arg == Py_True) ? 1.f : 0.f;
}
if (PyNumber_Check(arg)) {
return PyGLM_Number_AsFloat(PyGLM_GetNumber(arg));
PyObject* num = PyGLM_GetNumber(arg);
float f = PyGLM_Number_AsFloat(num);
Py_DECREF(num);
return f;
}
PyErr_SetString(PyExc_Exception, "supplied argument is not a number (this should not occur)");
return -1.0f;
Expand Down
1 change: 1 addition & 0 deletions PyGLM/internal_functions/type_checkers.h
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ struct PyGLMTypeInfo {
allocate(sizeof(view.len));
memcpy(data, view.buf, sizeof(view.len));
}
PyBuffer_Release(&view);
return;
} // end of getbuffer checking

Expand Down

0 comments on commit fbc82c8

Please sign in to comment.