5353static int ping_callback_ref ;
5454static int ping_host_count ;
5555static ip_addr_t ping_host_ip ;
56+ struct ping_option * ping_opt = NULL ;
5657
5758void ping_received (void * arg , void * data ) {
5859 // this would require change of the interface
@@ -89,7 +90,11 @@ void ping_received(void *arg, void *data) {
8990}
9091
9192static void ping_by_hostname (const char * name , ip_addr_t * ipaddr , void * arg ) {
92- struct ping_option * ping_opt = (struct ping_option * )c_zalloc (sizeof (struct ping_option ));
93+ if (!ping_opt ) {
94+ ping_opt = (struct ping_option * )c_zalloc (sizeof (struct ping_option ));
95+ } else {
96+ os_memset (ping_opt , 0 , sizeof (struct ping_option ));
97+ }
9398
9499 if (ipaddr == NULL ) {
95100 c_printf ("SEVERE problem resolving hostname - network and DNS accessible?\n" );
@@ -137,7 +142,7 @@ static int net_info_ping(lua_State *L)
137142{
138143 const char * ping_target ;
139144 unsigned count = 4 ;
140-
145+
141146 // retrieve address arg (mandatory)
142147 if (lua_isstring (L , 1 )) {
143148 ping_target = luaL_checkstring (L , 1 );
@@ -162,15 +167,19 @@ static int net_info_ping(lua_State *L)
162167 uint32 ip = ipaddr_addr (ping_target );
163168
164169 if (ip != IPADDR_NONE ) {
165- struct ping_option * ping_opt = (struct ping_option * )c_zalloc (sizeof (struct ping_option ));
170+ if (!ping_opt ) {
171+ ping_opt = (struct ping_option * )c_zalloc (sizeof (struct ping_option ));
172+ } else {
173+ os_memset (ping_opt , 0 , sizeof (struct ping_option ));
174+ }
175+
166176
167177 ping_opt -> count = count ;
168178 ping_opt -> ip = ip ;
169179 ping_opt -> coarse_time = 0 ;
170180 ping_opt -> recv_function = & ping_received ;
171181
172182 ping_start (ping_opt );
173-
174183 } else {
175184 ping_host_count = count ;
176185
0 commit comments