Fix memory leak with drmModeGetConnectorCurrent()

drmModeGetConnectorCurrent() must provide temporary storage for the
kernel to fill in at least one mode (asking for !=0 modes is how
you prevent the heavyweight probe in the kernel). Currently we malloc
that temp storage but we fail to free it before overwriting the
pointer with the address of the actual storage we use to store the
real mode list we get from the kernel in the second ioctl call.

Let's just keep the temporary storage on the stack and thus we avoid the
leak and also eliminate some pointless mallocs.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Fixes: 5ed5fa1060 ("mode: Retrieve only the current information for a Connector")
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
main
Ville Syrjälä 2015-12-15 14:18:32 +02:00
parent 242f77ce03
commit e342c0fc25
1 changed files with 7 additions and 4 deletions

View File

@ -475,12 +475,13 @@ _drmModeGetConnector(int fd, uint32_t connector_id, int probe)
{
struct drm_mode_get_connector conn, counts;
drmModeConnectorPtr r = NULL;
struct drm_mode_modeinfo stack_mode;
memclear(conn);
conn.connector_id = connector_id;
if (!probe) {
conn.count_modes = 1;
conn.modes_ptr = VOID2U64(drmMalloc(sizeof(struct drm_mode_modeinfo)));
conn.modes_ptr = VOID2U64(&stack_mode);
}
if (drmIoctl(fd, DRM_IOCTL_MODE_GETCONNECTOR, &conn))
@ -504,7 +505,7 @@ retry:
goto err_allocs;
} else {
conn.count_modes = 1;
conn.modes_ptr = VOID2U64(drmMalloc(sizeof(struct drm_mode_modeinfo)));
conn.modes_ptr = VOID2U64(&stack_mode);
}
if (conn.count_encoders) {
@ -525,6 +526,7 @@ retry:
counts.count_encoders < conn.count_encoders) {
drmFree(U642VOID(conn.props_ptr));
drmFree(U642VOID(conn.prop_values_ptr));
if (U642VOID(conn.modes_ptr) != &stack_mode)
drmFree(U642VOID(conn.modes_ptr));
drmFree(U642VOID(conn.encoders_ptr));
@ -567,6 +569,7 @@ retry:
err_allocs:
drmFree(U642VOID(conn.prop_values_ptr));
drmFree(U642VOID(conn.props_ptr));
if (U642VOID(conn.modes_ptr) != &stack_mode)
drmFree(U642VOID(conn.modes_ptr));
drmFree(U642VOID(conn.encoders_ptr));