diff --git a/src/sharedspice.c b/src/sharedspice.c index acc814887..60db65a49 100644 --- a/src/sharedspice.c +++ b/src/sharedspice.c @@ -965,12 +965,15 @@ ngSpice_Init(SendChar* printfcn, SendStat* statusfcn, ControlledExit* ngspiceexi struct passwd *pw; pw = getpwuid(getuid()); - s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR); + if (pw) { + s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR); - if (access(s, 0) == 0) - inp_source(s); + if (access(s, 0) == 0) { + inp_source(s); + } - tfree(s); + tfree(s); + } } #else /* ~ HAVE_PWD_H */ /* load user's initialisation file diff --git a/src/tclspice.c b/src/tclspice.c index 7e8e47b92..b98668a05 100644 --- a/src/tclspice.c +++ b/src/tclspice.c @@ -2525,10 +2525,15 @@ Spice_Init(Tcl_Interp *interp) struct passwd *pw; pw = getpwuid(getuid()); - s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR); + if (pw) { + s = tprintf("%s" DIR_PATHSEP "%s", pw->pw_dir, INITSTR); - if (access(s, 0) == 0) - inp_source(s); + if (access(s, 0) == 0) { + inp_source(s); + } + + tfree(s); + } } #else /* ~ HAVE_PWD_H */ {