53
53
static int ping_callback_ref ;
54
54
static int ping_host_count ;
55
55
static ip_addr_t ping_host_ip ;
56
+ struct ping_option * ping_opt = NULL ;
56
57
57
58
void ping_received (void * arg , void * data ) {
58
59
// this would require change of the interface
@@ -89,7 +90,11 @@ void ping_received(void *arg, void *data) {
89
90
}
90
91
91
92
static 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
+ }
93
98
94
99
if (ipaddr == NULL ) {
95
100
c_printf ("SEVERE problem resolving hostname - network and DNS accessible?\n" );
@@ -137,7 +142,7 @@ static int net_info_ping(lua_State *L)
137
142
{
138
143
const char * ping_target ;
139
144
unsigned count = 4 ;
140
-
145
+
141
146
// retrieve address arg (mandatory)
142
147
if (lua_isstring (L , 1 )) {
143
148
ping_target = luaL_checkstring (L , 1 );
@@ -162,15 +167,19 @@ static int net_info_ping(lua_State *L)
162
167
uint32 ip = ipaddr_addr (ping_target );
163
168
164
169
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
+
166
176
167
177
ping_opt -> count = count ;
168
178
ping_opt -> ip = ip ;
169
179
ping_opt -> coarse_time = 0 ;
170
180
ping_opt -> recv_function = & ping_received ;
171
181
172
182
ping_start (ping_opt );
173
-
174
183
} else {
175
184
ping_host_count = count ;
176
185
0 commit comments