Hi Alok,

I think I found memory leaks:

Le 26/03/2012 11:40, Alok Barsode a écrit :
From: Alok Barsode<[email protected]>

Fixes BMC#24997.
---
  include/timeserver.h |    3 +-
  plugins/meego.c      |    4 +-
  src/clock.c          |   16 +++++++--
  src/timeserver.c     |   85 ++------------------------------------------------
  4 files changed, 18 insertions(+), 90 deletions(-)

diff --git a/include/timeserver.h b/include/timeserver.h
index d124537..2a45384 100644
--- a/include/timeserver.h
+++ b/include/timeserver.h
@@ -26,8 +26,7 @@
  extern "C" {
  #endif

-int __connman_timeserver_system_append(const char *server);
-int __connman_timeserver_system_remove(const char *server);
+int __connman_timeserver_system_set(const char *server);

  #ifdef __cplusplus
  }
diff --git a/plugins/meego.c b/plugins/meego.c
index f8d2f0f..903f542 100644
--- a/plugins/meego.c
+++ b/plugins/meego.c
@@ -31,12 +31,12 @@

  static int meego_init(void)
  {
-       return __connman_timeserver_system_append(MEEGO_NTP_SERVER);
+       return __connman_timeserver_system_set(MEEGO_NTP_SERVER);
  }

  static void meego_exit(void)
  {
-       __connman_timeserver_system_remove(MEEGO_NTP_SERVER);
+
  }

  CONNMAN_PLUGIN_DEFINE(meego, "MeeGo features plugin", VERSION,
diff --git a/src/clock.c b/src/clock.c
index c3644ea..9bade7e 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -260,23 +260,31 @@ static DBusMessage *set_property(DBusConnection *conn,
                                DBUS_TYPE_STRING,&strval);
        } else if (g_str_equal(name, "Timeservers") == TRUE) {
                DBusMessageIter entry;
+               char *str = NULL;

                if (type != DBUS_TYPE_ARRAY)
                        return __connman_error_invalid_arguments(msg);

                dbus_message_iter_recurse(&value,&entry);

-               if (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_INVALID)
-                       __connman_timeserver_system_append(NULL);
-
                while (dbus_message_iter_get_arg_type(&entry) == 
DBUS_TYPE_STRING) {
                        const char *val;

                        dbus_message_iter_get_basic(&entry,&val);
-                       __connman_timeserver_system_append(val);
+
+                       if (str == NULL)
+                               str = g_strdup(val);
+                       else {
+                               char *temp = g_strdup_printf(" %s", val);
+                               str = g_strconcat(str, temp, NULL);
memory leak: g_strconcat() returns a new pointer, so here you are loosing orginal str value.
Actually, no need of g_strconcat():
char *temp = g_strdup_printf("%s %s", str, val);
g_free(str);
str = temp;
+                               g_free(temp);
+                       }
+
                        dbus_message_iter_next(&entry);
                }

+               __connman_timeserver_system_set(str);
You do not free str here nor in __connman_timeserver_system_set() so I guess there is a memory leak here.

Cheers,

Tomasz

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to