Skip to content

Commit 5f15c0d

Browse files
DanielNivgregkh
authored andcommitted
media: media/saa7164: fix saa7164_encoder_register() memory leak bugs
[ Upstream commit c759b2970c561e3b56aa030deb13db104262adfe ] Add a fix for the memory leak bugs that can occur when the saa7164_encoder_register() function fails. The function allocates memory without explicitly freeing it when errors occur. Add a better error handling that deallocate the unused buffers before the function exits during a fail. Signed-off-by: Daniel Niv <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent c369883 commit 5f15c0d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

drivers/media/pci/saa7164/saa7164-encoder.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
10301030
"(errno = %d), NO PCI configuration\n",
10311031
__func__, result);
10321032
result = -ENOMEM;
1033-
goto failed;
1033+
goto fail_pci;
10341034
}
10351035

10361036
/* Establish encoder defaults here */
@@ -1084,7 +1084,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
10841084
100000, ENCODER_DEF_BITRATE);
10851085
if (hdl->error) {
10861086
result = hdl->error;
1087-
goto failed;
1087+
goto fail_hdl;
10881088
}
10891089

10901090
port->std = V4L2_STD_NTSC_M;
@@ -1102,7 +1102,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
11021102
printk(KERN_INFO "%s: can't allocate mpeg device\n",
11031103
dev->name);
11041104
result = -ENOMEM;
1105-
goto failed;
1105+
goto fail_hdl;
11061106
}
11071107

11081108
port->v4l_device->ctrl_handler = hdl;
@@ -1113,10 +1113,7 @@ int saa7164_encoder_register(struct saa7164_port *port)
11131113
if (result < 0) {
11141114
printk(KERN_INFO "%s: can't register mpeg device\n",
11151115
dev->name);
1116-
/* TODO: We're going to leak here if we don't dealloc
1117-
The buffers above. The unreg function can't deal wit it.
1118-
*/
1119-
goto failed;
1116+
goto fail_reg;
11201117
}
11211118

11221119
printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
@@ -1138,9 +1135,14 @@ int saa7164_encoder_register(struct saa7164_port *port)
11381135

11391136
saa7164_api_set_encoder(port);
11401137
saa7164_api_get_encoder(port);
1138+
return 0;
11411139

1142-
result = 0;
1143-
failed:
1140+
fail_reg:
1141+
video_device_release(port->v4l_device);
1142+
port->v4l_device = NULL;
1143+
fail_hdl:
1144+
v4l2_ctrl_handler_free(hdl);
1145+
fail_pci:
11441146
return result;
11451147
}
11461148

0 commit comments

Comments
 (0)