Skip to content

Commit 841933d

Browse files
committed
getpwuid(mingw): initialize the structure only once
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 73ba9ee commit 841933d

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

compat/mingw.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,16 +1934,27 @@ int mingw_getpagesize(void)
19341934

19351935
struct passwd *getpwuid(int uid)
19361936
{
1937+
static unsigned initialized;
19371938
static char user_name[100];
1938-
static struct passwd p;
1939+
static struct passwd *p;
1940+
DWORD len;
1941+
1942+
if (initialized)
1943+
return p;
19391944

1940-
DWORD len = sizeof(user_name);
1941-
if (!GetUserName(user_name, &len))
1945+
len = sizeof(user_name);
1946+
if (!GetUserName(user_name, &len)) {
1947+
initialized = 1;
19421948
return NULL;
1943-
p.pw_name = user_name;
1944-
p.pw_gecos = "unknown";
1945-
p.pw_dir = NULL;
1946-
return &p;
1949+
}
1950+
1951+
p = xmalloc(sizeof(*p));
1952+
p->pw_name = user_name;
1953+
p->pw_gecos = "unknown";
1954+
p->pw_dir = NULL;
1955+
1956+
initialized = 1;
1957+
return p;
19471958
}
19481959

19491960
static HANDLE timer_event;

0 commit comments

Comments
 (0)