Skip to content

Commit cca115d

Browse files
stephenxsliat-grozovik
authored andcommitted
[Mellanox] Fix the memory leak in mlnx-sfpd (#3128)
* fix the memory leak in on_pmpe. objects created via sx_api having convention new_<type_name> should be release explicitly via delete_<type_name>. * avoid duplicate code.
1 parent 0ed8c81 commit cca115d

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

platform/mellanox/mlnx-sfpd/scripts/mlnx-sfpd

+24-20
Original file line numberDiff line numberDiff line change
@@ -205,36 +205,40 @@ class MlnxSfpd:
205205
pkt = new_uint8_t_arr(pkt_size)
206206
recv_info_p = new_sx_receive_info_t_p()
207207
pmpe_t = sx_event_pmpe_t()
208-
logical_port_list = new_sx_port_log_id_t_arr(4)
209208
port_attributes_list = new_sx_port_attributes_t_arr(64)
210209
port_cnt_p = new_uint32_t_p()
211210
uint32_t_p_assign(port_cnt_p,64)
212211
label_port_list = []
213-
status = True
214212
module_state = 0
215213

216214
rc = sx_lib_host_ifc_recv(fd_p, pkt, pkt_size_p, recv_info_p)
217215
if rc != 0:
218216
log_error("sx_lib_host_ifc_recv exited with error, rc %d" % rc)
219217
status = False
220-
return status, label_port_list, module_state
221-
222-
pmpe_t = recv_info_p.event_info.pmpe
223-
port_list_size = pmpe_t.list_size
224-
logical_port_list = pmpe_t.log_port_list
225-
module_state = pmpe_t.module_state
226-
227-
for i in xrange(port_list_size):
228-
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
229-
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
230-
port_cnt = uint32_t_p_value(port_cnt_p)
231-
232-
for i in xrange(port_cnt):
233-
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
234-
if port_attributes.log_port == logical_port:
235-
lable_port = port_attributes.port_mapping.module_port
236-
break
237-
label_port_list.append(lable_port)
218+
else:
219+
status = True
220+
pmpe_t = recv_info_p.event_info.pmpe
221+
port_list_size = pmpe_t.list_size
222+
logical_port_list = pmpe_t.log_port_list
223+
module_state = pmpe_t.module_state
224+
225+
for i in xrange(port_list_size):
226+
logical_port = sx_port_log_id_t_arr_getitem(logical_port_list, i)
227+
rc = sx_api_port_device_get(self.handle, 1 , 0, port_attributes_list, port_cnt_p)
228+
port_cnt = uint32_t_p_value(port_cnt_p)
229+
230+
for i in xrange(port_cnt):
231+
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
232+
if port_attributes.log_port == logical_port:
233+
lable_port = port_attributes.port_mapping.module_port
234+
break
235+
label_port_list.append(lable_port)
236+
237+
delete_uint32_t_p(pkt_size_p)
238+
delete_uint8_t_arr(pkt)
239+
delete_sx_receive_info_t_p(recv_info_p)
240+
delete_sx_port_attributes_t_arr(port_attributes_list)
241+
delete_uint32_t_p(port_cnt_p)
238242

239243
return status, label_port_list, module_state,
240244

0 commit comments

Comments
 (0)