nphilipp / python-slip

Convenience, extension and workaround code for Python and some Python modules.
GNU General Public License v2.0
2 stars 7 forks source link

memory leak may occur #9

Open zhuofeng6 opened 1 year ago

zhuofeng6 commented 1 year ago

Is there something wrong with this code? Object.connections_smobjs[self.connection] = \

One firewall corresponds to one connection. Therefore, there is only one connection. So it go in if self.connection not in Object.connections_senders the first time, and never get in again. This code (Object.connections_smobjs[self.connection] = \ )should not be indented.

If indented, then connections_senders will only increase and never remove. The memory will leak this way. Am i right?

Because we encountered a memory leak on firewalld, the final location is this indentation caused. I look forward to your reply, although you don't maintain slip anymore

    def sender_seen(self, sender):
        if (sender, self.connection) not in Object.senders:
            Object.senders.add((sender, self.connection))
            if self.connection not in Object.connections_senders:
                Object.connections_senders[self.connection] = set()
                Object.connections_smobjs[self.connection] = \
                    self.connection.add_signal_receiver(
                        handler_function=self._name_owner_changed,
                        signal_name='NameOwnerChanged',
                        dbus_interface='org.freedesktop.DBus',
                        arg1=sender)
            Object.connections_senders[self.connection].add(sender)

maybe it is correct

    def sender_seen(self, sender):
        if (sender, self.connection) not in Object.senders:
            Object.senders.add((sender, self.connection))
            if self.connection not in Object.connections_senders:
                Object.connections_senders[self.connection] = set()
            Object.connections_smobjs[self.connection] = \
                self.connection.add_signal_receiver(
                    handler_function=self._name_owner_changed,
                    signal_name='NameOwnerChanged',
                    dbus_interface='org.freedesktop.DBus',
                    arg1=sender)
            Object.connections_senders[self.connection].add(sender)