After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 655461 - mrp_time_from_tm() free memory which becomes of environment
mrp_time_from_tm() free memory which becomes of environment
Status: RESOLVED FIXED
Product: planner
Classification: Other
Component: General
0.14.x
Other Linux
: Normal normal
: ---
Assigned To: planner-maint
planner-maint
Depends on:
Blocks:
 
 
Reported: 2011-07-28 00:36 UTC by Maxim Zakharov
Modified: 2013-03-11 20:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix for freeing memory becoming of the environment (773 bytes, patch)
2011-07-28 00:36 UTC, Maxim Zakharov
needs-work Details | Review
Avoid an access violation caused by freeing memory given through putenv. (1.24 KB, patch)
2013-03-08 22:10 UTC, Luis Menina
committed Details | Review

Description Maxim Zakharov 2011-07-28 00:36:00 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.
Comment 1 Luis Menina 2013-03-08 21:32:14 UTC
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.
Comment 2 Luis Menina 2013-03-08 22:10:30 UTC
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.
Comment 3 Alexandre Franke 2013-03-11 17:22:09 UTC
Review of attachment 238425 [details] [review]:

Please push this and close this bug afterwards.
Comment 4 Luis Menina 2013-03-11 20:36:42 UTC
Attachment 238425 [details] pushed as c6af975 - Avoid an access violation caused by freeing memory given through putenv.