Commit f315fd355ffaec6a9ad541081975ac821404256e
Committed by
David S. Miller
1 parent
c95567c803
Exists in
master
and in
20 other branches
caif: Fixed potential memory leak
Rearranged the allocation and packet creations to avoid potential leaks in error path. Signed-off-by: Kim Lilliestierna <kim.xx.lilliestierna@stericsson.com> Signed-off-by: Sjur Brændeland <sjur.brandeland@stericssion.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 1 changed file with 9 additions and 8 deletions Side-by-side Diff
net/caif/cfctrl.c
... | ... | @@ -175,15 +175,17 @@ |
175 | 175 | |
176 | 176 | void cfctrl_enum_req(struct cflayer *layer, u8 physlinkid) |
177 | 177 | { |
178 | + struct cfpkt *pkt; | |
178 | 179 | struct cfctrl *cfctrl = container_obj(layer); |
179 | - struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | |
180 | 180 | struct cflayer *dn = cfctrl->serv.layer.dn; |
181 | - if (!pkt) | |
182 | - return; | |
181 | + | |
183 | 182 | if (!dn) { |
184 | 183 | pr_debug("not able to send enum request\n"); |
185 | 184 | return; |
186 | 185 | } |
186 | + pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | |
187 | + if (!pkt) | |
188 | + return; | |
187 | 189 | caif_assert(offsetof(struct cfctrl, serv.layer) == 0); |
188 | 190 | init_info(cfpkt_info(pkt), cfctrl); |
189 | 191 | cfpkt_info(pkt)->dev_info->id = physlinkid; |
190 | 192 | |
191 | 193 | |
192 | 194 | |
... | ... | @@ -302,18 +304,17 @@ |
302 | 304 | struct cflayer *client) |
303 | 305 | { |
304 | 306 | int ret; |
307 | + struct cfpkt *pkt; | |
305 | 308 | struct cfctrl *cfctrl = container_obj(layer); |
306 | - struct cfpkt *pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | |
307 | 309 | struct cflayer *dn = cfctrl->serv.layer.dn; |
308 | 310 | |
309 | - if (!pkt) | |
310 | - return -ENOMEM; | |
311 | - | |
312 | 311 | if (!dn) { |
313 | 312 | pr_debug("not able to send link-down request\n"); |
314 | 313 | return -ENODEV; |
315 | 314 | } |
316 | - | |
315 | + pkt = cfpkt_create(CFPKT_CTRL_PKT_LEN); | |
316 | + if (!pkt) | |
317 | + return -ENOMEM; | |
317 | 318 | cfpkt_addbdy(pkt, CFCTRL_CMD_LINK_DESTROY); |
318 | 319 | cfpkt_addbdy(pkt, channelid); |
319 | 320 | init_info(cfpkt_info(pkt), cfctrl); |