[ZBX-11959] Memory leak in agent if built on OpenBSD Created: 2017 Mar 23  Updated: 2024 Apr 10  Resolved: 2017 Mar 30

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Agent (G)
Affects Version/s: 2.2.17, 3.0.8, 3.2.4, 3.4.0alpha1
Fix Version/s: 3.4.0alpha1

Type: Incident report Priority: Minor
Reporter: Andrea Biscuola (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: agent, memoryleak
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OpenBSD 6.1-CURRENT


Team: Team C
Team: Team C
Sprint: Sprint 4
Story Points: 0.5

 Description   

The standard if_nameindex() function, dynamically allocate an array of structures with informations regarding network devices.
The structure should be released once used with if_freenameindex(), this is never done:

int	NET_IF_DISCOVERY(AGENT_REQUEST *request, AGENT_RESULT *result)
{
	int			i;
	struct zbx_json		j;
	struct if_nameindex	*interfaces;

	if (NULL == (interfaces = if_nameindex()))
	{
		SET_MSG_RESULT(result, zbx_dsprintf(NULL, "Cannot obtain system information: %s", zbx_strerror(errno)));
		return SYSINFO_RET_FAIL;
	}

	zbx_json_init(&j, ZBX_JSON_STAT_BUF_LEN);

	zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);

	for (i = 0; 0 != interfaces[i].if_index; i++)
	{
		zbx_json_addobject(&j, NULL);
		zbx_json_addstring(&j, "{#IFNAME}", interfaces[i].if_name, ZBX_JSON_TYPE_STRING);
		zbx_json_close(&j);
	}

	zbx_json_close(&j);

	SET_STR_RESULT(result, strdup(j.buffer));

	zbx_json_free(&j);

	return SYSINFO_RET_OK;
}

Spotted using the llvm static analyzer



 Comments   
Comment by Andrea Biscuola (Inactive) [ 2017 Mar 23 ]

OpenBSD is not the only platform that implement if_nameindex(). A fast check show the fact that the freebsd and netbsd code also are affected. Don't know about all the other supported OS

Comment by Andrea Biscuola (Inactive) [ 2017 Mar 24 ]

Fixed in svn://svn.zabbix.com/branches/dev/ZBX-11959

Simply added if_freenameindex() before returning. Note that there is no need for a NULL check as in all the affected platforms, if_freenameindex() boils down to free(ptr).

Comment by Rostislav Palivoda [ 2017 Mar 29 ]

andris Please test & code review.

Comment by Andris Mednis [ 2017 Mar 29 ]

Reviewed. See proposed small change in r66895.

abs The proposed changes are ok. No functional changes anyway there, approved.

Comment by Andrea Biscuola (Inactive) [ 2017 Mar 29 ]

Fixed in:

  • pre-2.2.17
  • pre-3.0.8
  • pre-3.2.4
  • 3.4.0alpha1 (trunk)
Generated at Tue Apr 16 11:53:47 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.