Skip to content

Commit 7651186

Browse files
committed
fixed memory leaks and python ownership problems
1 parent 9bf0f71 commit 7651186

6 files changed

Lines changed: 12 additions & 7 deletions

File tree

include/flock/cxx/group.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class GroupHandle {
194194
flock_group_handle_t gh;
195195
auto err = flock_group_handle_create_from_file(client, filename, mode, &gh);
196196
FLOCK_CONVERT_AND_THROW(err);
197-
return GroupHandle{gh};
197+
return GroupHandle{gh, false};
198198
}
199199

200200
/**
@@ -223,7 +223,7 @@ class GroupHandle {
223223
auto err = flock_group_handle_create_from_serialized(
224224
client, serialized_view.data(), serialized_view.size(), mode, &gh);
225225
FLOCK_CONVERT_AND_THROW(err);
226-
return GroupHandle{gh};
226+
return GroupHandle{gh, false};
227227
}
228228

229229
/**

python/mochi/flock/test_client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ def test_init_client_from_address(self):
1111
def test_init_client_from_engine(self):
1212
with Engine("na+sm") as engine:
1313
client = mfc.Client(engine)
14-
del client
1514

1615

1716
if __name__ == '__main__':

python/mochi/flock/test_provider.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def test_init_provider(self):
1818
initial_view = view.GroupView()
1919
initial_view.members.add(address, 42)
2020
provider = mfs.Provider(engine, 42, json.dumps(config), initial_view)
21-
del provider
2221
engine.finalize()
2322

2423

python/src/py-flock-client.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,24 @@ PYBIND11_MODULE(pyflock_client, m) {
3838
},
3939
"Create a GroupHandle instance",
4040
"address"_a,
41-
"provider_id"_a=0)
41+
"provider_id"_a=0,
42+
py11::keep_alive<0,1>())
4243
.def("make_group_handle_from_file",
4344
[](const flock::Client& client,
4445
const std::string& filename) {
4546
return flock::GroupHandle::FromFile(client, filename.c_str());
4647
},
4748
"Create a GroupHandle instance",
48-
"filename"_a)
49+
"filename"_a,
50+
py11::keep_alive<0,1>())
4951
.def("make_group_handle_from_serialized",
5052
[](const flock::Client& client,
5153
std::string_view serialized) {
5254
return flock::GroupHandle::FromSerialized(client, serialized);
5355
},
5456
"Create a GroupHandle instance",
55-
"serialized"_a)
57+
"serialized"_a,
58+
py11::keep_alive<0,1>())
5659
;
5760
py11::class_<flock::GroupHandle, std::shared_ptr<flock::GroupHandle>>(m, "GroupHandle")
5861
.def("update", &flock::GroupHandle::update)

src/centralized/centralized-backend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,7 @@ static flock_return_t centralized_destroy_group(void* ctx)
10361036
if(context->get_view_rpc_id) margo_deregister(context->mid, context->get_view_rpc_id);
10371037
if(context->membership_update_rpc_id) margo_deregister(context->mid, context->membership_update_rpc_id);
10381038
if(context->leave_rpc_id) margo_deregister(context->mid, context->leave_rpc_id);
1039+
if(context->primary.address) margo_addr_free(context->mid, context->primary.address);
10391040
if(context->config) json_object_put(context->config);
10401041
flock_group_view_clear(&context->view);
10411042
free(context);

src/provider.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,8 @@ flock_return_t flock_provider_register(
263263
if(provider)
264264
*provider = p;
265265

266+
margo_instance_ref_incr(mid);
267+
266268
margo_trace(mid, "[flock] Provider registered with ID %d", (int)provider_id);
267269

268270
finish:
@@ -301,6 +303,7 @@ static void flock_finalize_provider(void* p)
301303
free(provider->self_addr_str);
302304
margo_instance_id mid = provider->mid;
303305
free(provider);
306+
margo_instance_release(mid);
304307
margo_trace(mid, "[flock] Provider successfuly finalized");
305308
}
306309

0 commit comments

Comments
 (0)