GNOME Bugzilla – Bug 655461
mrp_time_from_tm() free memory which becomes of environment
Last modified: 2013-03-11 20:36:46 UTC
Created attachment 192783 [details] [review] fix for freeing memory becoming of the environment mrp_time_from_tm() free memory which becomes of environment thus the valgrind complains as follow: ==4022== Invalid read of size 2 ==4022== at 0x4CD5914: getenv (getenv.c:84) ==4022== by 0x4C34930: g_getenv (in /lib/libglib-2.0.so.0.2400.1) ==4022== by 0x4BB4D8A: ??? (in /usr/lib/libgconf-2.so.4.1.5) ==4022== by 0x4B6A51D: g_type_class_ref (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4B504C1: g_object_newv (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4B50A47: g_object_new (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4BB4B14: gconf_client_get_default (in /usr/lib/libgconf-2.so.4.1.5) ==4022== by 0x807423C: conf_get_gconf_client (planner-conf-gconf.c:37) ==4022== by 0x807453E: planner_conf_dir_exists (planner-conf-gconf.c:56) ==4022== by 0x805F784: planner_window_new (planner-window.c:2053) ==4022== by 0x805D315: planner_application_new_window (planner-application.c:243) ==4022== by 0x805CE88: main (planner-main.c:88) ==4022== Address 0x5633930 is 0 bytes inside a block of size 20 free'd ==4022== at 0x4024B3A: free (vg_replace_malloc.c:366) ==4022== by 0x4C07FC5: g_free (in /lib/libglib-2.0.so.0.2400.1) ==4022== by 0x405F4E3: mrp_time_from_tm (mrp-time.c:181) ==4022== by 0x405F523: mrp_time_current_time (mrp-time.c:206) ==4022== by 0x4050D9A: project_init (mrp-project.c:422) ==4022== by 0x4B6A9C1: g_type_create_instance (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4B4EA17: ??? (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4B50189: g_object_newv (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4B50A47: g_object_new (in /usr/lib/libgobject-2.0.so.0.2400.1) ==4022== by 0x4050C3E: mrp_project_new (mrp-project.c:649) ==4022== by 0x805F6F7: planner_window_new (planner-window.c:1678) ==4022== by 0x805D315: planner_application_new_window (planner-application.c:243) The attached patches solves the issue.
Review of attachment 192783 [details] [review]: ::: libplanner/mrp-time.c @@ -179,3 @@ tmp = g_strconcat ("TZ=", old_tz, NULL); putenv (tmp); - g_free (tmp); By removing the call to g_free, you trade the access violation for a memory leak.
Created attachment 238425 [details] [review] Avoid an access violation caused by freeing memory given through putenv. Strings given to the environment through putenv can't be freed as long as they are used by the environment. g_setenv doesn't have this problem.
Review of attachment 238425 [details] [review]: Please push this and close this bug afterwards.
Attachment 238425 [details] pushed as c6af975 - Avoid an access violation caused by freeing memory given through putenv.