@@ -13672,30 +13672,35 @@ PyObject *igraphmodule_Graph_community_leiden(igraphmodule_GraphObject *self,
1367213672 if (!error && membership == 0) {
1367313673 start = 0;
1367413674 membership = (igraph_vector_int_t*)calloc(1, sizeof(igraph_vector_int_t));
13675- if (membership== 0) {
13675+ if (membership == 0) {
1367613676 PyErr_NoMemory();
1367713677 error = -1;
13678- } else {
13679- igraph_vector_int_init(membership, 0);
13678+ } else if (igraph_vector_int_init(membership, 0)) {
13679+ igraphmodule_handle_igraph_error();
13680+ error = -1;
1368013681 }
1368113682 }
1368213683
13683- if (PyObject_IsTrue(normalize_resolution))
13684+ if (!error && PyObject_IsTrue(normalize_resolution))
1368413685 {
1368513686 /* If we need to normalize the resolution parameter,
1368613687 * we will need to have node weights. */
1368713688 if (node_weights == 0)
1368813689 {
1368913690 node_weights = (igraph_vector_t*)calloc(1, sizeof(igraph_vector_t));
13690- if (node_weights== 0) {
13691+ if (node_weights == 0) {
1369113692 PyErr_NoMemory();
1369213693 error = -1;
13693- } else {
13694- igraph_vector_init(node_weights, 0);
13695- if (igraph_strength(&self->g, node_weights, igraph_vss_all(), IGRAPH_ALL, 0, edge_weights)) {
13696- igraphmodule_handle_igraph_error();
13697- error = -1;
13698- }
13694+ } else if (igraph_vector_init(node_weights, 0)) {
13695+ igraphmodule_handle_igraph_error();
13696+ error = -1;
13697+ } else if (igraph_strength(
13698+ &self->g, node_weights, igraph_vss_all(),
13699+ igraph_is_directed(&self->g) ? IGRAPH_OUT : IGRAPH_ALL,
13700+ IGRAPH_NO_LOOPS, edge_weights
13701+ )) {
13702+ igraphmodule_handle_igraph_error();
13703+ error = -1;
1369913704 }
1370013705 }
1370113706 resolution /= igraph_vector_sum(node_weights);
0 commit comments