Questing about the use of libmm

Aleksander Morgado aleksander at aleksander.es
Mon Feb 8 11:57:13 UTC 2016


Hey,

See some inline comments.


On Mon, Feb 8, 2016 at 11:35 AM, Troels Olesen <to at movis.dk> wrote:
> Here is an example code of my problem with MMManager* memory leak.
>
> ---------------
> #include <iostream>
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> #include <glib.h>
>
> // HACK: 'class' is a reserved keyword in C++
> #ifdef __cplusplus
> extern "C" {
> # define class modemClass
> #endif
>
> #include <libmm-glib.h>
>
> #if __cplusplus
> # undef class
> } //Extern C
> #endif
>
> using namespace std;
>
> void GetModemState()
> {
>     GError *error = NULL;
>
>     // Get Gdbus Connection
>     GDBusConnection *connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL,
> &error);
>
>     if(!connection)
>     {
>         g_warning("GetModemState : Failed to get gdbus connection");
>         g_error_free(error);

return;

>     }
>
>     // Get MMModemManager
>     MMManager *manager = mm_manager_new_sync(connection,
> G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_DO_NOT_AUTO_START, NULL, &error);
>
>     if(!manager)
>     {
>         g_warning("GetModemState : Failed to get MMManager");
>         g_error_free(error);

g_object_unref(connection);
return;

>     }
>
>     // Get list of Modems.
>     GList *modem_list =
> g_dbus_object_manager_get_objects(G_DBUS_OBJECT_MANAGER(manager));


if (!modem_list)
{
    g_warning("No modems detected");
    g_object_unref(manager);
    g_object_unref(connection);
    return;
}

>
>     // Select first modem. and set it as MMObject.
>     MMObject* object = MM_OBJECT(modem_list->data);
>
>     // Get MMModem. (peek)
>     MMModem *modem = mm_object_peek_modem(object);
>
>     // Get MMModemState
>     MMModemState modem_state = mm_modem_get_state(modem);
>
>     cout << "Modem state is : " << modem_state << endl;
>
>     // Free glist modems.
>     g_list_free_full(modem_list, (GDestroyNotify)g_object_unref);
>
>     // Clear pointer referances.
>     g_object_unref(manager);
>     g_object_unref(connection);
> }
>
>
> int main()
> {
>
>     gboolean run = true;
>     int count = 0;
>     while(run)
>     {
>         GetModemState();
>
>         cout << "count : " << count << endl;
>         if(count > 100000)
>             run = false;
>
>         count++;
>         //sleep(1);
>     }
>
>     return 0;
> }
> -------------
>
> When this code is run, it leaks about 0,6kb memery pr. loop.
>

How are you measuring the memory leaks?

I get 0 definitely lost leaks in my valgrind report with your tester.
Also, which GLib/GIO version are you using?

-- 
Aleksander
https://aleksander.es


More information about the ModemManager-devel mailing list