diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2020-11-04 09:45:29 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2020-11-04 09:51:14 +0100 |
commit | f21fde38559141e382ad64f8ce048d73c7e197a4 (patch) | |
tree | 5de5dc1d2965eb0ea826e26489b4abc185f228e5 | |
parent | 2d28969df74c687cfc4ea03dee6317874525e313 (diff) |
cinterion: fix port reference leaks
The mm_base_modem_get_port_*() returns a full reference, we should use
the mm_base_modem_peek_port_*() methods instead. Also, refactor a bit
the logic because both ports are really configured in the same way, so
just apply the same setup to both.
-rw-r--r-- | plugins/cinterion/mm-broadband-modem-cinterion.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index 6ad44725..35e20334 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -2817,33 +2817,24 @@ static void setup_ports (MMBroadbandModem *_self) { MMBroadbandModemCinterion *self = (MM_BROADBAND_MODEM_CINTERION (_self)); - MMPortSerialAt *port; + MMPortSerialAt *ports[2]; + guint i; /* Call parent's setup ports first always */ MM_BROADBAND_MODEM_CLASS (mm_broadband_modem_cinterion_parent_class)->setup_ports (_self); - /* Primary */ - port = mm_base_modem_get_port_primary (MM_BASE_MODEM (self)); - if (port) { - mm_port_serial_at_add_unsolicited_msg_handler ( - port, - self->priv->sysstart_regex, - NULL, NULL, NULL); - mm_port_serial_at_add_unsolicited_msg_handler ( - port, - self->priv->scks_regex, - NULL, NULL, NULL); - } + ports[0] = mm_base_modem_peek_port_primary (MM_BASE_MODEM (self)); + ports[1] = mm_base_modem_peek_port_secondary (MM_BASE_MODEM (self)); - /* Secondary */ - port = mm_base_modem_get_port_secondary (MM_BASE_MODEM (self)); - if (port) { + for (i = 0; i < G_N_ELEMENTS (ports); i++) { + if (!ports[i]) + continue; mm_port_serial_at_add_unsolicited_msg_handler ( - port, + ports[i], self->priv->sysstart_regex, NULL, NULL, NULL); mm_port_serial_at_add_unsolicited_msg_handler ( - port, + ports[i], self->priv->scks_regex, NULL, NULL, NULL); } |