Skip to content

Commit 58b19c0

Browse files
author
vsky
committed
Memory leak "fix"
1 parent a3b978e commit 58b19c0

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

app/modules/net_info.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
static int ping_callback_ref;
5454
static int ping_host_count;
5555
static ip_addr_t ping_host_ip;
56+
struct ping_option *ping_opt = NULL;
5657

5758
void 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

9192
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+
}
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

Comments
 (0)