Fixed use of freed memory.
This commit is contained in:
parent
0ff6cdf5b1
commit
12c95723b7
|
@ -52,6 +52,8 @@ CArchFileUnix::getBasename(const char* pathname)
|
||||||
std::string
|
std::string
|
||||||
CArchFileUnix::getUserDirectory()
|
CArchFileUnix::getUserDirectory()
|
||||||
{
|
{
|
||||||
|
char* buffer = NULL;
|
||||||
|
std::string dir;
|
||||||
#if HAVE_GETPWUID_R
|
#if HAVE_GETPWUID_R
|
||||||
struct passwd pwent;
|
struct passwd pwent;
|
||||||
struct passwd* pwentp;
|
struct passwd* pwentp;
|
||||||
|
@ -63,18 +65,16 @@ CArchFileUnix::getUserDirectory()
|
||||||
#else
|
#else
|
||||||
long size = BUFSIZ;
|
long size = BUFSIZ;
|
||||||
#endif
|
#endif
|
||||||
char* buffer = new char[size];
|
buffer = new char[size];
|
||||||
getpwuid_r(getuid(), &pwent, buffer, size, &pwentp);
|
getpwuid_r(getuid(), &pwent, buffer, size, &pwentp);
|
||||||
delete[] buffer;
|
|
||||||
#else
|
#else
|
||||||
struct passwd* pwentp = getpwuid(getuid());
|
struct passwd* pwentp = getpwuid(getuid());
|
||||||
#endif
|
#endif
|
||||||
if (pwentp != NULL && pwentp->pw_dir != NULL) {
|
if (pwentp != NULL && pwentp->pw_dir != NULL) {
|
||||||
return pwentp->pw_dir;
|
dir = pwentp->pw_dir;
|
||||||
}
|
|
||||||
else {
|
|
||||||
return std::string();
|
|
||||||
}
|
}
|
||||||
|
delete[] buffer;
|
||||||
|
return dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
|
|
Loading…
Reference in New Issue