/soc/2012/sanket/statscollector-2.x.y: bb859a1c5296: Allocate g_...

Sanket Agarwal sanket at soc.pidgin.im
Sun Apr 7 21:05:22 EDT 2013


Changeset: bb859a1c529639d6d9697d280f48d4deb64815f6
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2013-04-07 17:05 +0530
Branch:	 soc.2012.statscollector
URL: https://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/bb859a1c5296

Description:

Allocate g_strdup_printf's to char * and free them upon use.

diffstat:

 libpurple/plugins/statscollector.c |  59 ++++++++++++++++++++++++++-----------
 1 files changed, 41 insertions(+), 18 deletions(-)

diffs (158 lines):

diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -155,6 +155,8 @@ save_xml()
         data = xmlnode_to_formatted_str(nroot, NULL);
         purple_util_write_data_to_file("stats.xml", data, -1);
 
+        g_free(version);
+
         xmlnode_free(nroot);
         g_free(data);
 }
@@ -221,19 +223,21 @@ refresh_public_server_cache_cb(PurpleUti
                                         (void *)hash_id,
                                         NULL);
                         }
-                        //public_server_handle = purple_timeout_add_seconds(
-                        //        PUBLIC_SERVER_CACHE_REFRESH,
-                        //        refresh_public_server_cache,
-                        //        NULL);
+                        public_server_handle = purple_timeout_add_seconds(
+                                PUBLIC_SERVER_CACHE_REFRESH,
+                                refresh_public_server_cache,
+                                NULL);
 
                         /* Re-evaluate accounts for public domains in usernames. */
                         loaded_accounts = purple_accounts_get_all_active();
                         g_list_foreach(loaded_accounts, (GFunc)acc_sign_on_event, NULL);
                 }
         } else {
-                // public_server_handle = purple_timeout_add_seconds(
-                //        10, refresh_public_server_cache, NULL);
+                 public_server_handle = purple_timeout_add_seconds(
+                        10, refresh_public_server_cache, NULL);
         }
+
+        g_free(header);
 }
 
 /* Refresh the stored cache of information about IRC/Jabber
@@ -272,10 +276,16 @@ static xmlnode *
 get_app_32_64()
 {
         int pt_size;
+        char *pt_size_str;
         xmlnode *bit_size_xml;
+
         pt_size = sizeof(int *)*8;
         bit_size_xml = xmlnode_new("app-bit");
-        xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d",pt_size), -1);
+        pt_size_str = g_strdup_printf("%d", pt_size);
+        xmlnode_insert_data(bit_size_xml, pt_size_str, -1);
+
+        g_free(pt_size_str);
+
         return bit_size_xml;
 }
 
@@ -395,6 +405,7 @@ get_os_name()
         /* Define variables corresponding to different OS */
 #ifdef _WIN32
         xmlnode *major_version, *minor_version;
+        char *major_version_str, *minor_version_str;
         OSVERSIONINFO osvi;
 #elif defined __APPLE__
         size_t length;
@@ -406,6 +417,7 @@ get_os_name()
         xmlnode *product_version_xml;
         xmlnode *dict_sys_ver_xml, *key_sys_ver_xml, *value_sys_ver_xml;
         xmlnode *major_version_xml, *minor_version_xml, *bug_version_xml;
+        char *major_version_str, *minor_version_str, *bug_version_str;
 
         /* Get handle for Gestalt by dlopen */
         int (*gestalt_ext)(int, int *);
@@ -441,14 +453,17 @@ get_os_name()
         GetVersionEx(&osvi);
         major_version = xmlnode_new("major-version");
         minor_version = xmlnode_new("minor-version");
+        major_version_str = g_strdup_printf("%d", osvi.dwMajorVersion);
+        minor_version_str = g_strdup_printf("%d", osvi.dwMinorVersion);
 
-        xmlnode_insert_data(major_version,
-                        g_strdup_printf("%d",osvi.dwMajorVersion),-1);
-        xmlnode_insert_data(minor_version,
-                        g_strdup_printf("%d",osvi.dwMinorVersion),-1);
+        xmlnode_insert_data(major_version, major_version_str, -1);
+        xmlnode_insert_data(minor_version, minor_version_str, -1);
 
         xmlnode_insert_child(os_name_xml, major_version);
         xmlnode_insert_child(os_name_xml, minor_version);
+
+        g_free(major_version_str);
+        g_free(minor_version_str);
 #elif defined __APPLE__
         major_version_xml = xmlnode_new("major-version");
         minor_version_xml = xmlnode_new("minor-version");
@@ -464,17 +479,21 @@ get_os_name()
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
         if (gestalt_ext) {
+                major_version_str = g_strdup_printf("%d", major_version);
+                minor_version_str = g_strdup_printf("%d", minor_version);
+                bug_version_str = g_strdup_printf("%d", bug_version);
 
-                xmlnode_insert_data(major_version_xml,
-                                g_strdup_printf("%d", major_version), -1);
-                xmlnode_insert_data(minor_version_xml,
-                                g_strdup_printf("%d", minor_version), -1);
-                xmlnode_insert_data(bug_version_xml,
-                                g_strdup_printf("%d", bug_fix_version), -1);
+                xmlnode_insert_data(major_version_xml, major_version_str, -1);
+                xmlnode_insert_data(minor_version_xml, minor_version_str, -1);
+                xmlnode_insert_data(bug_version_xml, bug_version_str, -1);
 
                 xmlnode_insert_child(os_name_xml, major_version_xml);
                 xmlnode_insert_child(os_name_xml, minor_version_xml);
                 xmlnode_insert_child(os_name_xml, bug_version_xml);
+
+                g_free(major_version_str);
+                g_free(minor_version_str);
+                g_free(bug_version_str);
         } else
 #endif /* MAC OS X > 10.4 */
         {
@@ -732,6 +751,7 @@ acc_sign_on_event(PurpleAccount *account
                                         value_md5_tag);
                         xmlnode_insert_data(user_split_node_hash, value_md5, -1);
 
+                        g_free(value);
                         g_free(value_md5);
                         g_free(value_md5_tag);
                         g_free(split_text);
@@ -829,6 +849,7 @@ send_stats()
         g_free(path);
         g_free(request);
         g_free(pd_xml);
+        g_free(postdata);
 
         return FALSE;
 }
@@ -965,7 +986,7 @@ init_stats(PurplePlugin *plugin)
         purple_debug_info("STATS", "allocating new hash tables ....");
 
         /* Refresh the public server cache */
-        // refresh_public_server_cache(NULL);
+        refresh_public_server_cache(NULL);
 
         /* Check if the version is compatible with the plugin,
          * this should generally change when we install a new
@@ -1207,6 +1228,8 @@ get_plugin_pref_frame(PurplePlugin *plug
         purple_plugin_pref_set_type(ts, PURPLE_PLUGIN_PREF_INFO);
         purple_plugin_pref_frame_add(frame, ts);
 
+        g_free(ts_str);
+
         return frame;
 }
 



More information about the Commits mailing list