FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix incorrect `Py_XDECREF/Py_DECREF` call on stolen reference after `PyList_SetItem` failure by wr-web · Pull Request #885 · igraph/python-igraph · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (8) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
14 changes: 0 additions & 14 deletions src/_igraph/attributes.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ PyObject* igraphmodule_i_create_edge_attribute(const igraph_t* graph,
Py_INCREF(Py_None);
if (PyList_SetItem(values, i, Py_None)) { /* reference stolen */
Py_DECREF(values);
Py_DECREF(Py_None);
return 0;
}
}
Expand Down Expand Up @@ -659,7 +658,6 @@ static igraph_error_t igraphmodule_i_attribute_add_vertices(

if (o) {
if (PyList_SetItem(value, i + j, o)) {
Py_DECREF(o); /* append failed */
o = NULL; /* indicate error */
} else {
/* reference stolen by the list */
Expand Down Expand Up @@ -721,7 +719,6 @@ static igraph_error_t igraphmodule_i_attribute_permute_vertices(const igraph_t *
Py_INCREF(o);
if (PyList_SetItem(newlist, i, o)) {
PyErr_PrintEx(0);
Py_DECREF(o);
Py_DECREF(newlist);
Py_DECREF(newdict);
IGRAPH_ERROR("", IGRAPH_FAILURE);
Expand Down Expand Up @@ -878,7 +875,6 @@ static igraph_error_t igraphmodule_i_attribute_add_edges(

if (o) {
if (PyList_SetItem(value, i + j, o)) {
Py_DECREF(o); /* append failed */
o = NULL; /* indicate error */
} else {
/* reference stolen by the list */
Expand Down Expand Up @@ -935,7 +931,6 @@ static igraph_error_t igraphmodule_i_attribute_permute_edges(const igraph_t *gra
Py_INCREF(o);
if (PyList_SetItem(newlist, i, o)) {
PyErr_PrintEx(0);
Py_DECREF(o);
Py_DECREF(newlist);
Py_DECREF(newdict);
IGRAPH_ERROR("", IGRAPH_FAILURE);
Expand Down Expand Up @@ -982,7 +977,6 @@ static PyObject* igraphmodule_i_ac_func(PyObject* values,
Py_INCREF(item);

if (PyList_SetItem(list, j, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(res);
return 0;
}
Expand Down Expand Up @@ -1070,7 +1064,6 @@ static PyObject* igraphmodule_i_ac_sum(PyObject* values,

item = PyFloat_FromDouble(sum);
if (PyList_SetItem(res, i, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(res);
return 0;
}
Expand Down Expand Up @@ -1114,7 +1107,6 @@ static PyObject* igraphmodule_i_ac_prod(PyObject* values,
/* reference to new float stolen */
item = PyFloat_FromDouble((double)prod);
if (PyList_SetItem(res, i, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(res);
return 0;
}
Expand Down Expand Up @@ -1147,7 +1139,6 @@ static PyObject* igraphmodule_i_ac_first(PyObject* values,

Py_INCREF(item);
if (PyList_SetItem(res, i, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(res);
return 0;
}
Expand Down Expand Up @@ -1207,7 +1198,6 @@ static PyObject* igraphmodule_i_ac_random(PyObject* values,

Py_INCREF(item);
if (PyList_SetItem(res, i, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(random_func);
Py_DECREF(res);
return 0;
Expand Down Expand Up @@ -1244,7 +1234,6 @@ static PyObject* igraphmodule_i_ac_last(PyObject* values,
Py_INCREF(item);

if (PyList_SetItem(res, i, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(res);
return 0;
}
Expand Down Expand Up @@ -1290,7 +1279,6 @@ static PyObject* igraphmodule_i_ac_mean(PyObject* values,
/* reference to new float stolen */
item = PyFloat_FromDouble((double)mean);
if (PyList_SetItem(res, i, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(res);
return 0;
}
Expand Down Expand Up @@ -1324,7 +1312,6 @@ static PyObject* igraphmodule_i_ac_median(PyObject* values,

Py_INCREF(item);
if (PyList_SetItem(list, j, item)) { /* reference to item stolen */
Py_DECREF(item);
Py_DECREF(list);
Py_DECREF(res);
return 0;
Expand Down Expand Up @@ -1383,7 +1370,6 @@ static PyObject* igraphmodule_i_ac_median(PyObject* values,

/* reference to item stolen */
if (PyList_SetItem(res, i, item)) {
Py_DECREF(item);
Py_DECREF(list);
Py_DECREF(res);
return 0;
Expand Down
3 changes: 0 additions & 3 deletions src/_igraph/edgeobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ int igraphmodule_Edge_set_attribute(igraphmodule_EdgeObject* self, PyObject* k,
* It took me 1.5 hours between London and Manchester to figure it out */
Py_INCREF(v);
r=PyList_SetItem(result, self->idx, v);
if (r == -1) { Py_DECREF(v); }
return r;
}

Expand All @@ -406,15 +405,13 @@ int igraphmodule_Edge_set_attribute(igraphmodule_EdgeObject* self, PyObject* k,
if (i != self->idx) {
Py_INCREF(Py_None);
if (PyList_SetItem(result, i, Py_None) == -1) {
Py_DECREF(Py_None);
Py_DECREF(result);
return -1;
}
} else {
/* Same game with the reference count here */
Py_INCREF(v);
if (PyList_SetItem(result, i, v) == -1) {
Py_DECREF(v);
Py_DECREF(result);
return -1;
}
Expand Down
8 changes: 0 additions & 8 deletions src/_igraph/edgeseqobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ PyObject* igraphmodule_EdgeSeq_get_attribute_values(igraphmodule_EdgeSeqObject*
Py_INCREF(item);

if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Expand All @@ -335,7 +334,6 @@ PyObject* igraphmodule_EdgeSeq_get_attribute_values(igraphmodule_EdgeSeqObject*
Py_INCREF(item);

if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Expand All @@ -359,7 +357,6 @@ PyObject* igraphmodule_EdgeSeq_get_attribute_values(igraphmodule_EdgeSeqObject*
Py_INCREF(item);

if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Expand Down Expand Up @@ -495,7 +492,6 @@ int igraphmodule_EdgeSeq_set_attribute_values_mapping(igraphmodule_EdgeSeqObject
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, i, item)) {
Py_DECREF(item);
return -1;
} /* PyList_SetItem stole a reference to the item automatically */
}
Expand All @@ -516,7 +512,6 @@ int igraphmodule_EdgeSeq_set_attribute_values_mapping(igraphmodule_EdgeSeqObject
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, i, item)) {
Py_DECREF(item);
Py_DECREF(list);
return -1;
}
Expand Down Expand Up @@ -560,7 +555,6 @@ int igraphmodule_EdgeSeq_set_attribute_values_mapping(igraphmodule_EdgeSeqObject
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, VECTOR(es)[i], item)) {
Py_DECREF(item);
igraph_vector_int_destroy(&es);
return -1;
} /* PyList_SetItem stole a reference to the item automatically */
Expand All @@ -579,7 +573,6 @@ int igraphmodule_EdgeSeq_set_attribute_values_mapping(igraphmodule_EdgeSeqObject
for (i = 0; i < n2; i++) {
Py_INCREF(Py_None);
if (PyList_SetItem(list, i, Py_None)) {
Py_DECREF(Py_None);
Py_DECREF(list);
return -1;
}
Expand All @@ -596,7 +589,6 @@ int igraphmodule_EdgeSeq_set_attribute_values_mapping(igraphmodule_EdgeSeqObject
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, VECTOR(es)[i], item)) {
Py_DECREF(item);
Py_DECREF(list);
return -1;
}
Expand Down
2 changes: 0 additions & 2 deletions src/_igraph/indexing.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ static int igraphmodule_i_Graph_adjmatrix_set_index_row(igraph_t* graph,
/* Setting attribute */
Py_INCREF(item);
if (PyList_SetItem(values, eid, item)) {
Py_DECREF(item);
igraph_vector_int_clear(&data->to_add);
}
}
Expand Down Expand Up @@ -402,7 +401,6 @@ static int igraphmodule_i_Graph_adjmatrix_set_index_row(igraph_t* graph,
/* Setting attribute */
Py_INCREF(new_value);
if (PyList_SetItem(values, eid, new_value)) {
Py_DECREF(new_value);
igraph_vector_int_clear(&data->to_add);
}
}
Expand Down
4 changes: 0 additions & 4 deletions src/_igraph/operators.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ PyObject *igraphmodule__union(PyObject *self,
if (!dest || PyList_SetItem(emi, j, dest)) {
igraph_vector_ptr_destroy(&gs);
igraph_vector_int_list_destroy(&edgemaps);
Py_XDECREF(dest);
Py_DECREF(emi);
Py_DECREF(em_list);
return NULL;
Expand All @@ -167,7 +166,6 @@ PyObject *igraphmodule__union(PyObject *self,
if (!emi || PyList_SetItem(em_list, i, emi)) {
igraph_vector_ptr_destroy(&gs);
igraph_vector_int_list_destroy(&edgemaps);
Py_XDECREF(emi);
Py_DECREF(em_list);
return NULL;
}
Expand Down Expand Up @@ -281,7 +279,6 @@ PyObject *igraphmodule__intersection(PyObject *self,
if (!dest || PyList_SetItem(emi, j, dest)) {
igraph_vector_ptr_destroy(&gs);
igraph_vector_int_list_destroy(&edgemaps);
Py_XDECREF(dest);
Py_DECREF(emi);
Py_DECREF(em_list);
return NULL;
Expand All @@ -292,7 +289,6 @@ PyObject *igraphmodule__intersection(PyObject *self,
if (!emi || PyList_SetItem(em_list, i, emi)) {
igraph_vector_ptr_destroy(&gs);
igraph_vector_int_list_destroy(&edgemaps);
Py_XDECREF(emi);
Py_DECREF(em_list);
return NULL;
}
Expand Down
7 changes: 3 additions & 4 deletions src/_igraph/pyhelpers.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ PyObject* igraphmodule_PyList_NewFill(Py_ssize_t len, PyObject* item) {
for (i = 0; i < len; i++) {
Py_INCREF(item);
if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Py_DECREF(result);
return 0;
}
}

return result;
Expand Down
5 changes: 0 additions & 5 deletions src/_igraph/vertexobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ int igraphmodule_Vertex_set_attribute(igraphmodule_VertexObject* self, PyObject*
* It took me 1.5 hours between London and Manchester to figure it out */
Py_INCREF(v);
r=PyList_SetItem(result, self->idx, v);
if (r == -1) { Py_DECREF(v); }
return r;
}

Expand All @@ -537,15 +536,13 @@ int igraphmodule_Vertex_set_attribute(igraphmodule_VertexObject* self, PyObject*
if (i != self->idx) {
Py_INCREF(Py_None);
if (PyList_SetItem(result, i, Py_None) == -1) {
Py_DECREF(Py_None);
Py_DECREF(result);
return -1;
}
} else {
/* Same game with the reference count here */
Py_INCREF(v);
if (PyList_SetItem(result, i, v) == -1) {
Py_DECREF(v);
Py_DECREF(result);
return -1;
}
Expand Down Expand Up @@ -639,7 +636,6 @@ static PyObject* _convert_to_edge_list(igraphmodule_VertexObject* vertex, PyObje
}

if (PyList_SetItem(obj, i, edge)) { /* reference to v stolen, reference to idx discarded */
Py_DECREF(edge);
return NULL;
}
}
Expand Down Expand Up @@ -684,7 +680,6 @@ static PyObject* _convert_to_vertex_list(igraphmodule_VertexObject* vertex, PyOb
}

if (PyList_SetItem(obj, i, v)) { /* reference to v stolen, reference to idx discarded */
Py_DECREF(v);
return NULL;
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/_igraph/vertexseqobject.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ PyObject* igraphmodule_VertexSeq_get_attribute_values(igraphmodule_VertexSeqObje
Py_INCREF(item);

if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Expand All @@ -320,7 +319,6 @@ PyObject* igraphmodule_VertexSeq_get_attribute_values(igraphmodule_VertexSeqObje
Py_INCREF(item);

if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Expand All @@ -343,7 +341,6 @@ PyObject* igraphmodule_VertexSeq_get_attribute_values(igraphmodule_VertexSeqObje
Py_INCREF(item);

if (PyList_SetItem(result, i, item)) {
Py_DECREF(item);
Py_DECREF(result);
return 0;
}
Expand Down Expand Up @@ -469,7 +466,6 @@ int igraphmodule_VertexSeq_set_attribute_values_mapping(igraphmodule_VertexSeqOb
if (item == 0) return -1;
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, i, item)) {
Py_DECREF(item);
return -1;
} /* PyList_SetItem stole a reference to the item automatically */
}
Expand All @@ -487,7 +483,6 @@ int igraphmodule_VertexSeq_set_attribute_values_mapping(igraphmodule_VertexSeqOb
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, i, item)) {
Py_DECREF(item);
Py_DECREF(list);
return -1;
}
Expand Down Expand Up @@ -530,7 +525,6 @@ int igraphmodule_VertexSeq_set_attribute_values_mapping(igraphmodule_VertexSeqOb
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, VECTOR(vs)[i], item)) {
Py_DECREF(item);
igraph_vector_int_destroy(&vs);
return -1;
} /* PyList_SetItem stole a reference to the item automatically */
Expand All @@ -549,7 +543,6 @@ int igraphmodule_VertexSeq_set_attribute_values_mapping(igraphmodule_VertexSeqOb
for (i = 0; i < n2; i++) {
Py_INCREF(Py_None);
if (PyList_SetItem(list, i, Py_None)) {
Py_DECREF(Py_None);
Py_DECREF(list);
igraph_vector_int_destroy(&vs);
return -1;
Expand All @@ -566,7 +559,6 @@ int igraphmodule_VertexSeq_set_attribute_values_mapping(igraphmodule_VertexSeqOb
}
/* No need to Py_INCREF(item), PySequence_GetItem returns a new reference */
if (PyList_SetItem(list, VECTOR(vs)[i], item)) {
Py_DECREF(list);
Py_DECREF(item);
igraph_vector_int_destroy(&vs);
return -1;
Expand Down
Loading

Back | FazBrowse Home | New Git URL