Questing about the use of libmm

Dan Williams dcbw at redhat.com
Mon Feb 8 15:57:11 UTC 2016


On Mon, 2016-02-08 at 14:51 +0100, Troels Olesen wrote:
> Hi Aleksander.
> 
> i only checked the memory usage of the application with pmap, and 
> gnome-system-monitor. It seems like the memery use start around
> 900kb, 
> and then jumps up to 47-120 mb memory usage.
> 
> I have researched this memory bug a little more, and it fits quite
> well 
> with a bug in glib < 2.46.2.
> http://stackoverflow.com/questions/29823097/glib-memory-leak-when-cre
> ating-gdbusproxy
> 
> It looks like the leak is in the function "g_bus_get_sync", its not 
> exactly a leak, but a problem with glib's custom memory handler.
> 
> I am using Ubuntu 15.10, and it looks like it has not been patched
> yet. 
> Ubuntu is running glib-2.46.1-1.
> 
> But thanks for the inline comments.
> I still have one question left, about the MM structure.
> 
> When i have the MMObject* it seems like i can unref the MMManager*
> and 
> Gdbus connection, and still get data from the MMObject*.
> 
> Is this the correct way to handle this, or do i need to keep the
> gdbus 
> connection open, or does the MMObject* automatically handle that as
> long 
> as it is referenced.
> 
> Said with other words, is it ok to unref the MMManager* and gdbus 
> connection, after i get the MMObject* ?

They should hold references internally to the things they use, so this
should be OK to do though perhaps not recommended.  But if you ever
need to get another Modem object or listen to events on the manager, it
would be more efficient to keep the MMManager around instead of
destroying/creating it multiple times.

Dan

> 
> Den 08-02-2016 kl. 12:57 skrev Aleksander Morgado:
> > 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?
> > 
> 
> _______________________________________________
> ModemManager-devel mailing list
> ModemManager-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/modemmanager-devel


More information about the ModemManager-devel mailing list