wispr: Use g_strdup() instead of strdup()
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Wed, 2 May 2012 10:13:06 +0000 (13:13 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Wed, 2 May 2012 12:38:30 +0000 (15:38 +0300)
Valgrind reports following error if strdup() is used here:

==12572== Invalid read of size 4
==12572==    at 0x429113B: ??? (in /lib/libc-2.11.90.so)
==12572==    by 0x80A8154: wispr_route_request (wispr.c:471)
==12572==    by 0x805CA4F: resolv_result (gweb.c:449)
==12572==    by 0x805DD4B: sort_and_return_results (gresolv.c:494)
==12572==    by 0x805E285: received_udp_data (gresolv.c:705)
==12572==    by 0x40AD8E6: ??? (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x4078AFA: g_main_context_dispatch (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x407911E: ??? (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x40796BC: g_main_loop_run (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x807400F: main (main.c:508)
==12572==  Address 0x55f406c is 20 bytes inside a block of size 22 alloc'd
==12572==    at 0x4029AE9: malloc (vg_replace_malloc.c:236)
==12572==    by 0x40B1D6C: g_malloc (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x40B4C25: g_strdup (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x805CA23: resolv_result (gweb.c:1222)
==12572==    by 0x805DD4B: sort_and_return_results (gresolv.c:494)
==12572==    by 0x805E285: received_udp_data (gresolv.c:705)
==12572==    by 0x40AD8E6: ??? (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x4078AFA: g_main_context_dispatch (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x407911E: ??? (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x40796BC: g_main_loop_run (in /lib/libglib-2.0.so.0.2800.6)
==12572==    by 0x807400F: main (main.c:508)
==12572==

If g_strdup() is used then no error is printed.
This error does not make much sense but anyway use g_strdup()
like in other parts of this file.

src/wispr.c

index 034cced..f44a21a 100644 (file)
@@ -468,7 +468,7 @@ static gboolean wispr_route_request(const char *address, int ai_family,
                return FALSE;
        }
 
-       route->address = strdup(address);
+       route->address = g_strdup(address);
        route->if_index = if_index;
        wp_context->route_list = g_slist_prepend(wp_context->route_list, route);