Navigation Menu

Skip to content

Commit

Permalink
win32-launcher: Cleanup PATH to fix R6034 (msvcr90.dll, bug 1489)
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Sep 9, 2014
1 parent 312cd86 commit 711b81f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
Binary file modified tools/win32-launcher/gpo.exe
Binary file not shown.
50 changes: 50 additions & 0 deletions tools/win32-launcher/gpodder.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");

Expand Down
Binary file modified tools/win32-launcher/gpodder.exe
Binary file not shown.

0 comments on commit 711b81f

Please sign in to comment.