Use snprintf instead of wsprintf, and use getenv("APPDATA") instead of
authorMagnus Hagander <magnus@hagander.net>
Tue, 23 Oct 2007 17:58:01 +0000 (17:58 +0000)
committerMagnus Hagander <magnus@hagander.net>
Tue, 23 Oct 2007 17:58:01 +0000 (17:58 +0000)
SHGetFolderPath.

This removes the direct dependency on shell32.dll and user32.dll, which
eats a lot of "desktop heap" for each backend that's started. The
desktop heap is a very limited resource, causing backends to no
longer start once it's been exhausted.

We still have indirect depdendencies on user32.dll through third party
libraries, but those can't easily be removed.

Dave Page

src/backend/port/win32/signal.c
src/port/kill.c
src/port/path.c

index 9c48df31142de3e1798e63f8c1bb73bd6b45373b..91bc95791932513a756d2723d6a7a93a0897e3d2 100644 (file)
@@ -178,7 +178,7 @@ pgwin32_create_signal_listener(pid_t pid)
        char            pipename[128];
        HANDLE          pipe;
 
-       wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%d", (int) pid);
+       snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%u", (int) pid);
 
        pipe = CreateNamedPipe(pipename, PIPE_ACCESS_DUPLEX,
                                           PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
@@ -251,7 +251,7 @@ pg_signal_thread(LPVOID param)
        char            pipename[128];
        HANDLE          pipe = pgwin32_initial_signal_pipe;
 
-       wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%d", GetCurrentProcessId());
+       snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%u", GetCurrentProcessId());
 
        for (;;)
        {
index 30f3b8e5fbfdf0b3fac979c4e5c181f8b6ec1af3..907f5e8c6f17d0510d482ebf0117ae8da21b5265 100644 (file)
@@ -38,7 +38,7 @@ pgkill(int pid, int sig)
                errno = EINVAL;
                return -1;
        }
-       wsprintf(pipename, "\\\\.\\pipe\\pgsignal_%i", pid);
+       snprintf(pipename, sizeof(pipename), "\\\\.\\pipe\\pgsignal_%u", pid);
        if (!CallNamedPipe(pipename, &sigData, 1, &sigRet, 1, &bytes, 1000))
        {
                if (GetLastError() == ERROR_FILE_NOT_FOUND)
index ba4be4000809fbaf5e0f54b441c8167ce148f815..acc3cdc26074853754552744ce938e7631e1dfd2 100644 (file)
@@ -628,10 +628,14 @@ get_home_path(char *ret_path)
        strlcpy(ret_path, pwd->pw_dir, MAXPGPATH);
        return true;
 #else
-       char            tmppath[MAX_PATH];
-
-       ZeroMemory(tmppath, sizeof(tmppath));
-       if (SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, tmppath) != S_OK)
+       char            *tmppath;
+
+    /*
+     * Note: We use getenv here because the more modern SHGetSpecialFolderPath()
+     * will force us to link with shell32.lib which eats valuable desktop heap.
+     */
+    tmppath = getenv("APPDATA");
+       if (!tmppath)
                return false;
        snprintf(ret_path, MAXPGPATH, "%s/postgresql", tmppath);
        return true;