egl/dri2: do not leak dri2_dpy->driver_name

Originally all hardware drivers duplicate the driver_name string
from an external source, while for the software rasterizer we set
it to "swrast". Follow the example set by hw drivers this way
we can free the string at dri2_terminate().

v2: Use strdup over strndup. Suggested by Ilia Mirkin.
v3: Handle platform_drm in a similar manner. Cleanup swrast
driver_name in error path.

Cc: Chia-I Wu <olv@lunarg.com>
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index c1497b8..eb6abfd 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -469,9 +469,7 @@
    struct dri2_egl_display *dri2_dpy = disp->DriverData;
    const __DRIextension **extensions;
 
-   dri2_dpy->driver_name = "swrast";
    extensions = dri2_open_driver(disp);
-
    if (!extensions)
       return EGL_FALSE;
 
@@ -673,6 +671,7 @@
    if (dri2_dpy->driver)
       dlclose(dri2_dpy->driver);
    free(dri2_dpy->device_name);
+   free(dri2_dpy->driver_name);
 
    switch (disp->Platform) {
 #ifdef HAVE_X11_PLATFORM