Skip to content

Commit 711b81f

Browse files
committed
win32-launcher: Cleanup PATH to fix R6034 (msvcr90.dll, bug 1489)
1 parent 312cd86 commit 711b81f

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

tools/win32-launcher/gpo.exe

2.33 KB
Binary file not shown.

tools/win32-launcher/gpodder.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@
2727
#include <windows.h>
2828
#include <shlobj.h>
2929

30+
#include <stdio.h>
3031
#include <stdlib.h>
3132
#include <shellapi.h>
3233
#include <string.h>
34+
#include <sys/stat.h>
35+
#include <stdbool.h>
3336

3437
#include "gpodder.h"
3538
#include "downloader.h"
@@ -81,6 +84,45 @@ const char *FindPythonDLL(HKEY rootKey)
8184
return result;
8285
}
8386

87+
bool contains_system_dll(const char *path, const char *filename)
88+
{
89+
bool result = false;
90+
struct stat st;
91+
92+
char *fn = malloc(strlen(path) + 1 + strlen(filename) + 1);
93+
sprintf(fn, "%s\\%s", path, filename);
94+
if (stat(fn, &st) == 0) {
95+
result = true;
96+
}
97+
free(fn);
98+
99+
return result;
100+
}
101+
102+
char *clean_path_variable(const char *path)
103+
{
104+
char *old_path = strdup(path);
105+
int length = strlen(path) + 1;
106+
char *new_path = (char *)malloc(length);
107+
memset(new_path, 0, length);
108+
109+
char *tok = strtok(old_path, ";");
110+
while (tok != NULL) {
111+
// Only add the path component if it doesn't contain msvcr90.dll
112+
if (!contains_system_dll(tok, "msvcr90.dll")) {
113+
if (strlen(new_path) > 0) {
114+
strcat(new_path, ";");
115+
}
116+
117+
strcat(new_path, tok);
118+
}
119+
120+
tok = strtok(NULL, ";");
121+
}
122+
123+
free(old_path);
124+
return new_path;
125+
}
84126

85127
int main(int argc, char** argv)
86128
{
@@ -140,6 +182,14 @@ int main(int argc, char** argv)
140182
}
141183
}
142184

185+
/**
186+
* Workaround for error R6034 (need to do this before Python DLL
187+
* is loaded, otherwise the runtime error will still show up)
188+
**/
189+
char *new_path = clean_path_variable(getenv("PATH"));
190+
SetEnvironmentVariable("PATH", new_path);
191+
free(new_path);
192+
143193
/* Only load the Python DLL after we've set up the environment */
144194
python_dll = LoadLibrary("python27.dll");
145195

tools/win32-launcher/gpodder.exe

2.83 KB
Binary file not shown.

0 commit comments

Comments
 (0)