# sdl12-compat: windows: if we overrode "windib" envvar, set it back.

**URL:** <https://discourse.libsdl.org/t/sdl12-compat-windows-if-we-overrode-windib-envvar-set-it-back/34003>\
**Category:** SDL Commits\
**Created:** [December 8, 2021, 4:46am UTC](https://discourse.libsdl.org/t/sdl12-compat-windows-if-we-overrode-windib-envvar-set-it-back/34003 "2021-12-08T04:46:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [December 8, 2021, 4:46am UTC](https://discourse.libsdl.org/t/sdl12-compat-windows-if-we-overrode-windib-envvar-set-it-back/34003/1 "2021-12-08T04:46:02Z")

</div>

> <https://github.com/libsdl-org/sdl12-compat/commit/b73b4e98484b110c5d4780a6f31e5d0e0962d47a>
>
> Removed allocation here, too, because we don't need it.

```diff
From b73b4e98484b110c5d4780a6f31e5d0e0962d47a Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 7 Dec 2021 23:44:02 -0500
Subject: [PATCH] windows: if we overrode "windib" envvar, set it back.

Removed allocation here, too, because we don't need it.
---
 src/SDL12_compat.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index adbe2d1..8a0e9e7 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1818,13 +1818,10 @@ SDL_InitSubSystem(Uint32 sdl12flags)
 #ifdef __WINDOWS__
     /* DOSBox (and probably other things), try to force the "windib" video
        backend, but it doesn't exist in SDL2. Force to "windows" instead. */
- char *origenv = NULL;
+ char *origvidenv = NULL;
     const char *env = SDL20_getenv("SDL_VIDEODRIVER");
     if (env && (SDL20_strcmp(env, "windib") == 0)) {
- origenv = SDL20_strdup(env);
- if (origenv == NULL) {
- return SDL20_OutOfMemory();
- }
+ origvidenv = "windib";
         SDL20_setenv("SDL_VIDEODRIVER", "windows", 1);
     }
 #endif
@@ -1857,7 +1854,9 @@ SDL_InitSubSystem(Uint32 sdl12flags)
     }
 
 #ifdef __WINDOWS__
- SDL20_free(origenv);
+ if (origvidenv) { /* set this back to minimize surprise state changes. */
+ SDL20_setenv("SDL_VIDEODRIVER", origvidenv, 1);
+ }
 #endif
 
     return rc;

```
