Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some resource leak issues #104

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lldp_dcbx.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ static void dcbx_free_data(struct dcbd_user_data *dud)

struct lldp_module * dcbx_register(void)
{
struct lldp_module *mod;
struct dcbd_user_data *dud;
struct lldp_module *mod = NULL;
struct dcbd_user_data *dud = NULL;
int dcbx_version;
int i;

Expand All @@ -385,7 +385,6 @@ struct lldp_module * dcbx_register(void)
}
dud = malloc(sizeof(*dud));
if (!dud) {
free(mod);
LLDPAD_ERR("failed to malloc LLDP DCBX module user data\n");
goto out_err;
}
Expand Down Expand Up @@ -431,6 +430,8 @@ struct lldp_module * dcbx_register(void)
LLDPAD_DBG("%s: dcbx register done\n", __func__);
return mod;
out_err:
free(mod);
free(dud);
LLDPAD_DBG("%s: dcbx register failed\n", __func__);
return NULL;
}
Expand Down
33 changes: 22 additions & 11 deletions lldp_dcbx_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,17 @@ static int get_state(char *ifname, __u8 *state)
NLMSG_ALIGN(sizeof(struct dcbmsg)));

if (d->cmd != DCB_CMD_GSTATE) {
return -EIO;
rval = -EIO;
goto out;
}
if (rta->rta_type != DCB_ATTR_STATE) {
rval = -EIO;
} else {
*state = *(__u8 *)NLA_DATA(rta);
}

out:
free(nlh);

return rval;
}

Expand Down Expand Up @@ -493,11 +494,15 @@ int get_dcb_capabilities(char *ifname,
rta_parent = (struct rtattr *)(((char *)d) +
NLMSG_ALIGN(sizeof(struct dcbmsg)));

if (d->cmd != DCB_CMD_GCAP)
return -EIO;
if (d->cmd != DCB_CMD_GCAP) {
rval = -EIO;
goto out;
}

if (rta_parent->rta_type != DCB_ATTR_CAP)
return -EIO;
if (rta_parent->rta_type != DCB_ATTR_CAP) {
rval = -EIO;
goto out;
}

rta_child = NLA_DATA(rta_parent);
rta_parent = (struct rtattr *)((char *)rta_parent +
Expand Down Expand Up @@ -540,6 +545,7 @@ int get_dcb_capabilities(char *ifname,
if (rta_parent != rta_child)
LLDPAD_DBG("rta pointers are off\n");

out:
free(nlh);
return rval;
}
Expand Down Expand Up @@ -580,11 +586,15 @@ int get_dcb_numtcs(const char *ifname, u8 *pgtcs, u8 *pfctcs)
rta_parent = (struct rtattr *)(((char *)d) +
NLMSG_ALIGN(sizeof(struct dcbmsg)));

if (d->cmd != DCB_CMD_GNUMTCS)
return -EIO;
if (d->cmd != DCB_CMD_GNUMTCS) {
rval = -EIO;
goto out;
}

if (rta_parent->rta_type != DCB_ATTR_NUMTCS)
return -EIO;
if (rta_parent->rta_type != DCB_ATTR_NUMTCS) {
rval = -EIO;
goto out;
}

rta_child = NLA_DATA(rta_parent);
rta_parent = (struct rtattr *)((char *)rta_parent +
Expand Down Expand Up @@ -618,9 +628,10 @@ int get_dcb_numtcs(const char *ifname, u8 *pgtcs, u8 *pfctcs)
if (rta_parent != rta_child)
LLDPAD_DBG("rta pointers are off\n");

free(nlh);
if (found != 3)
rval = -EIO;
out:
free(nlh);
return rval;
}

Expand Down
20 changes: 10 additions & 10 deletions lldp_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1280,16 +1280,16 @@ int get_arg_val_list(char *ibuf, int ilen, int *ioff,
p = (int *) realloc(arglens,
(i/NUM_ARGS + 1) * NUM_ARGS * sizeof(int));
if (!p) {
free(arglens);
return 0;
numargs = 0;
goto out;
} else {
arglens = p;
}
p = (int *) realloc(argvallens,
(i/NUM_ARGS + 1) * NUM_ARGS * sizeof(int));
if (!p) {
free(argvallens);
return 0;
numargs = 0;
goto out;
} else {
argvallens = p;
}
Expand All @@ -1312,21 +1312,21 @@ int get_arg_val_list(char *ibuf, int ilen, int *ioff,
*(argvallens+i) = argvalue_len;
}
} else {
free(arglens);
free(argvallens);
return 0;
numargs = 0;
goto out;
}
} else {
free(arglens);
free(argvallens);
return 0;
numargs = 0;
goto out;
}
}
numargs = i;
for (i = 0; i < numargs; i++) {
args[i][*(arglens+i)] = '\0';
argvals[i][*(argvallens+i)] = '\0';
}

out:
free(arglens);
free(argvallens);
return numargs;
Expand Down
2 changes: 1 addition & 1 deletion qbg/ecp.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,9 @@ static void ecp_rx_ProcessFrame(struct vdp_data *vd)
if ((tlv->type != TYPE_0) && !tlv_stored) {
LLDPAD_DBG("%s:%s TLV (%u) was not stored (%p)\n",
__func__, vd->ecp.ifname, tlv->type, tlv);
free_unpkd_tlv(tlv);
vd->ecp.stats.statsTLVsUnrecognizedTotal++;
}
free_unpkd_tlv(tlv);
tlv = NULL;
tlv_stored = false;
} while (tlv_offset < vd->ecp.rx.frame_len);
Expand Down
21 changes: 12 additions & 9 deletions qbg/ecp22.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,25 +932,25 @@ static int ecp22_req2send(char *ifname, unsigned short subtype,

LLDPAD_DBG("%s:%s subtype:%d\n", __func__, ifname, subtype);

eud = find_module_user_data_by_id(&lldp_mod_head, LLDP_MOD_ECP22);
ecp = find_ecpdata(ifname, eud);
if (!ecp) {
rc = -ENODEV;
goto out;
}
if (!ptlv) {
rc = -ENOMEM;
goto out;
}
if (ptlv->size >= ECP22_MAXPAYLOAD_LEN) {
rc = -E2BIG;
goto out;
goto err_out;
}

eud = find_module_user_data_by_id(&lldp_mod_head, LLDP_MOD_ECP22);
ecp = find_ecpdata(ifname, eud);
if (!ecp) {
rc = -ENODEV;
goto err_out;
}
payda = ecp22_getnode(&ecp->isfree);
if (!payda) {
free_pkd_tlv(ptlv);
rc = -ENOMEM;
goto out;
goto err_out;
}
payda->ptlv = ptlv;
payda->subtype = subtype;
Expand All @@ -959,6 +959,9 @@ static int ecp22_req2send(char *ifname, unsigned short subtype,
out:
LLDPAD_DBG("%s:%s rc:%d\n", __func__, ifname, rc);
return rc;
err_out:
free_pkd_tlv(ptlv);
goto out;
}

/*
Expand Down
Loading