From 2aaf2edccb5580890d5bc69d4d443584e430343a Mon Sep 17 00:00:00 2001 From: Martin Belanger Date: Tue, 2 May 2023 14:22:46 -0400 Subject: [PATCH] Python: Fix crash during garbage collection Same fix as commit d2a5491d1681ead6d8983d0bf6ecae937ab9f317 Prevent Garbage Collector (GC) from deleting host and root objects before all controller objects under that root/host have been GCed. This time, it's the init() method that needed the fix. Previously we had only fixed the connect() method. Signed-off-by: Martin Belanger --- libnvme/nvme.i | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libnvme/nvme.i b/libnvme/nvme.i index 9f97a4dc..8b461e6e 100644 --- a/libnvme/nvme.i +++ b/libnvme/nvme.i @@ -612,7 +612,9 @@ struct nvme_ns { %pythonappend nvme_ctrl::connect(struct nvme_host *h, struct nvme_fabrics_config *cfg) { - self.__parent = h # Keep a reference to parent to ensure garbage collection happens in the right order} + self.__host = h # Keep a reference to parent to ensure ctrl obj gets GCed before host} +%pythonappend nvme_ctrl::init(struct nvme_host *h, int instance) { + self.__host = h # Keep a reference to parent to ensure ctrl obj gets GCed before host} %extend nvme_ctrl { nvme_ctrl(struct nvme_root *r, const char *subsysnqn,