qcdm-serial-port: avoid playing with GByteArray internals

Since glib 2.32, we can use g_byte_array_new_take() to build a new GByteArray
from an own allocated buffer, so skip playing with the GByteArray internals.
This commit is contained in:
Aleksander Morgado
2013-04-02 13:31:31 +02:00
parent fc219be4d4
commit 678f596ff9
2 changed files with 13 additions and 10 deletions

View File

@@ -59,7 +59,7 @@ AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
PKG_CHECK_MODULES(MM,
glib-2.0 >= 2.30.2
glib-2.0 >= 2.32
gmodule-2.0
gobject-2.0
gio-2.0
@@ -68,7 +68,7 @@ AC_SUBST(MM_CFLAGS)
AC_SUBST(MM_LIBS)
PKG_CHECK_MODULES(LIBMM_GLIB,
glib-2.0 >= 2.30.2
glib-2.0 >= 2.32
gobject-2.0
gio-2.0
gio-unix-2.0)
@@ -76,7 +76,7 @@ AC_SUBST(LIBMM_GLIB_CFLAGS)
AC_SUBST(LIBMM_GLIB_LIBS)
PKG_CHECK_MODULES(MMCLI,
glib-2.0 >= 2.30.2
glib-2.0 >= 2.32
gobject-2.0
gio-2.0)
AC_SUBST(MMCLI_CFLAGS)

View File

@@ -81,6 +81,7 @@ handle_response (MMSerialPort *port,
{
MMQcdmSerialResponseFn response_callback = (MMQcdmSerialResponseFn) callback;
GByteArray *unescaped = NULL;
guint8 *unescaped_buffer;
GError *dm_error = NULL;
gsize used = 0;
gsize start = 0;
@@ -101,11 +102,10 @@ handle_response (MMSerialPort *port,
goto callback;
}
/* FIXME: don't munge around with byte array internals */
unescaped = g_byte_array_sized_new (1024);
unescaped_buffer = g_malloc (1024);
success = dm_decapsulate_buffer ((const char *) (response->data + start),
response->len - start,
(char *) unescaped->data,
(char *) unescaped_buffer,
1024,
&unescaped_len,
&used,
@@ -114,16 +114,19 @@ handle_response (MMSerialPort *port,
g_set_error_literal (&dm_error,
MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Failed to unescape QCDM packet.");
g_byte_array_free (unescaped, TRUE);
unescaped = NULL;
g_free (unescaped_buffer);
unescaped_buffer = NULL;
} else if (more) {
/* Need more data; we shouldn't have gotten here since the parse
* function checks for the end-of-frame marker, but whatever.
*/
g_free (unescaped_buffer);
return 0;
} else {
/* Successfully decapsulated the DM command */
unescaped->len = (guint) unescaped_len;
g_assert (unescaped_len <= 1024);
unescaped_buffer = g_realloc (unescaped_buffer, unescaped_len);
unescaped = g_byte_array_new_take (unescaped_buffer, unescaped_len);
}
callback:
@@ -133,7 +136,7 @@ callback:
callback_data);
if (unescaped)
g_byte_array_free (unescaped, TRUE);
g_byte_array_unref (unescaped);
g_clear_error (&dm_error);
return start + used;