Permalink
Browse files

win32-launcher: Cleanup PATH to fix R6034 (msvcr90.dll, bug 1489)

  • Loading branch information...
1 parent 312cd86 commit 711b81fd8f69f1919ed391705a28af13abd20faa @thp thp committed Sep 9, 2014
Binary file not shown.
@@ -27,9 +27,12 @@
#include <windows.h>
#include <shlobj.h>
+#include <stdio.h>
#include <stdlib.h>
#include <shellapi.h>
#include <string.h>
+#include <sys/stat.h>
+#include <stdbool.h>
#include "gpodder.h"
#include "downloader.h"
@@ -81,6 +84,45 @@ const char *FindPythonDLL(HKEY rootKey)
return result;
}
+bool contains_system_dll(const char *path, const char *filename)
+{
+ bool result = false;
+ struct stat st;
+
+ char *fn = malloc(strlen(path) + 1 + strlen(filename) + 1);
+ sprintf(fn, "%s\\%s", path, filename);
+ if (stat(fn, &st) == 0) {
+ result = true;
+ }
+ free(fn);
+
+ return result;
+}
+
+char *clean_path_variable(const char *path)
+{
+ char *old_path = strdup(path);
+ int length = strlen(path) + 1;
+ char *new_path = (char *)malloc(length);
+ memset(new_path, 0, length);
+
+ char *tok = strtok(old_path, ";");
+ while (tok != NULL) {
+ // Only add the path component if it doesn't contain msvcr90.dll
+ if (!contains_system_dll(tok, "msvcr90.dll")) {
+ if (strlen(new_path) > 0) {
+ strcat(new_path, ";");
+ }
+
+ strcat(new_path, tok);
+ }
+
+ tok = strtok(NULL, ";");
+ }
+
+ free(old_path);
+ return new_path;
+}
int main(int argc, char** argv)
{
@@ -140,6 +182,14 @@ int main(int argc, char** argv)
}
}
+ /**
+ * Workaround for error R6034 (need to do this before Python DLL
+ * is loaded, otherwise the runtime error will still show up)
+ **/
+ char *new_path = clean_path_variable(getenv("PATH"));
+ SetEnvironmentVariable("PATH", new_path);
+ free(new_path);
+
/* Only load the Python DLL after we've set up the environment */
python_dll = LoadLibrary("python27.dll");
Binary file not shown.

0 comments on commit 711b81f

Please sign in to comment.