Skip to content

Commit

Permalink
Fixed: Memory leak on unix-based platforms in the '~' home expansion …
Browse files Browse the repository at this point in the history
…algorithm Dir_ExpandHome (ouch) due to Str_Free being confused with Str_Delete.
  • Loading branch information
danij-deng committed Dec 1, 2010
1 parent d55953e commit 0fbd206
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions doomsday/engine/portable/src/sys_direc.c
Expand Up @@ -225,22 +225,22 @@ void Dir_FixSlashes(char* path, size_t len)
*/
void Dir_ExpandHome(char* str, size_t len)
{
ddstring_t *buf = NULL;
ddstring_t buf;

if(str[0] != '~')
return;

buf = Str_New();
Str_Init(&buf);

if(str[1] == '/')
{
// Replace it with the HOME environment variable.
Str_Set(buf, getenv("HOME"));
if(Str_RAt(buf, 0) != '/')
Str_Append(buf, "/");
Str_Set(&buf, getenv("HOME"));
if(Str_RAt(&buf, 0) != '/')
Str_Append(&buf, "/");

// Append the rest of the original path.
Str_Append(buf, str + 2);
Str_Append(&buf, str + 2);
}
else
{
Expand All @@ -253,19 +253,19 @@ void Dir_ExpandHome(char* str, size_t len)

if((pw = getpwnam(userName)) != NULL)
{
Str_Set(buf, pw->pw_dir);
if(Str_RAt(buf, 0) != '/')
Str_Append(buf, "/");
Str_Set(&buf, pw->pw_dir);
if(Str_RAt(&buf, 0) != '/')
Str_Append(&buf, "/");
}

Str_Append(buf, str + 1);
Str_Append(&buf, str + 1);
}

// Replace the original.
str[len - 1] = 0;
strncpy(str, Str_Text(buf), len - 1);
strncpy(str, Str_Text(&buf), len - 1);

Str_Free(buf);
Str_Free(&buf);
}
#endif

Expand Down

0 comments on commit 0fbd206

Please sign in to comment.