aboutsummaryrefslogtreecommitdiff
path: root/src/mm-port-serial.c
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@aleksander.es>2022-04-04 10:13:06 +0200
committerAleksander Morgado <aleksander@aleksander.es>2022-04-04 10:13:06 +0200
commit19f389949c2e15eb52a27d7b6236ef8a9ab76e97 (patch)
treec17381fa15928e1a23b4836c020ed3a43ad17d05 /src/mm-port-serial.c
parent210fa8bf354f5455a4e75dadbf69e72940b19d70 (diff)
port-serial: ensure the port object is valid after BUFFER_FULL handling
The BUFFER_FULL signal handler is effectively working in the same way as the response buffer processor, in both cases we may have scheduled the completion of the serial command, and that in turn may end up fully disposing the port object. We must make sure the port object is valid for as long as we need it in this function, so we take a reference while processing the response buffer. Fixes https://gitlab.freedesktop.org/mobile-broadband/ModemManager/-/issues/535
Diffstat (limited to 'src/mm-port-serial.c')
-rw-r--r--src/mm-port-serial.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/mm-port-serial.c b/src/mm-port-serial.c
index 8b6e34ec..3dedcab6 100644
--- a/src/mm-port-serial.c
+++ b/src/mm-port-serial.c
@@ -1017,13 +1017,6 @@ common_input_available (MMPortSerial *self,
serial_debug (self, "<--", buf, bytes_read);
g_byte_array_append (self->priv->response, (const guint8 *) buf, bytes_read);
- /* Make sure the response doesn't grow too long */
- if ((self->priv->response->len > SERIAL_BUF_SIZE) && self->priv->spew_control) {
- /* Notify listeners and then trim the buffer */
- g_signal_emit (self, signals[BUFFER_FULL], 0, self->priv->response);
- g_byte_array_remove_range (self->priv->response, 0, (SERIAL_BUF_SIZE / 2));
- }
-
/* See if we can parse anything. The response parsing may actually
* schedule the completion of a serial command, and that in turn may end
* up fully disposing this serial port object. In order to cope with
@@ -1032,6 +1025,13 @@ common_input_available (MMPortSerial *self,
* we should be keeping this socket/iochannel source or not. */
g_object_ref (self);
{
+ /* Make sure the response doesn't grow too long */
+ if ((self->priv->response->len > SERIAL_BUF_SIZE) && self->priv->spew_control) {
+ /* Notify listeners and then trim the buffer */
+ g_signal_emit (self, signals[BUFFER_FULL], 0, self->priv->response);
+ g_byte_array_remove_range (self->priv->response, 0, (SERIAL_BUF_SIZE / 2));
+ }
+
parse_response_buffer (self);
/* If we didn't end up closing the iochannel/socket in the previous