@@ -1612,18 +1612,34 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
16121612 goto err_out ;
16131613
16141614 if (info -> driverName ) {
1615- ds -> driverNames [0 ] = info -> driverName ;
1615+ ds -> driverNames [0 ] = strdup (info -> driverName );
1616+ if (!ds -> driverNames [0 ]) {
1617+ free (ds -> driverNames );
1618+ ds -> driverNames = NULL ;
1619+ goto err_out ;
1620+ }
16161621 } else {
1617- /* FIXME dri2_probe_driver_name() returns a strdup-ed string,
1618- * currently this gets leaked */
1619- ds -> driverNames [0 ] = ds -> driverNames [1 ] = dri2_probe_driver_name (pScreen , info );
1620- if (!ds -> driverNames [0 ])
1621- return FALSE;
1622+ ds -> driverNames [0 ] = dri2_probe_driver_name (pScreen , info );
1623+ if (!ds -> driverNames [0 ]) {
1624+ free (ds -> driverNames );
1625+ ds -> driverNames = NULL ;
1626+ goto err_out ;
1627+ }
16221628
16231629 /* There is no VDPAU driver for i965, fallback to the generic
16241630 * OpenGL/VAAPI va_gl backend to emulate VDPAU on i965. */
1625- if (strcmp (ds -> driverNames [0 ], "i965" ) == 0 )
1626- ds -> driverNames [1 ] = "va_gl" ;
1631+ if (strcmp (ds -> driverNames [0 ], "i965" ) == 0 ) {
1632+ ds -> driverNames [1 ] = strdup ("va_gl" );
1633+ } else {
1634+ ds -> driverNames [1 ] = strdup (ds -> driverNames [0 ]);
1635+ }
1636+
1637+ if (!ds -> driverNames [1 ]) {
1638+ free ((void * )ds -> driverNames [0 ]);
1639+ free (ds -> driverNames );
1640+ ds -> driverNames = NULL ;
1641+ goto err_out ;
1642+ }
16271643 }
16281644 }
16291645 else {
@@ -1671,7 +1687,12 @@ DRI2CloseScreen(ScreenPtr pScreen)
16711687
16721688 if (ds -> prime_id )
16731689 prime_id_allocate_bitmask &= ~(1 << ds -> prime_id );
1674- free (ds -> driverNames );
1690+ if (ds -> driverNames ) {
1691+ for (int i = 0 ; i < ds -> numDrivers ; i ++ ) {
1692+ free ((void * )ds -> driverNames [i ]);
1693+ }
1694+ free (ds -> driverNames );
1695+ }
16751696 free (ds );
16761697 dixSetPrivate (& pScreen -> devPrivates , dri2ScreenPrivateKey , NULL );
16771698}
0 commit comments