don't free non allocated memory

svn path=/trunk/; revision=11872
This commit is contained in:
Gunnar Dalsnes 2004-11-30 02:26:25 +00:00
parent fa6c7ae193
commit bcf7f5403f

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: environment.c,v 1.8 2004/10/10 18:26:33 ekohl Exp $ /* $Id: environment.c,v 1.9 2004/11/30 02:26:25 gdalsnes Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries * PROJECT: ReactOS system libraries
@ -34,15 +34,16 @@ SetUserEnvironmentVariable (LPVOID *Environment,
LPWSTR lpValue, LPWSTR lpValue,
BOOL bExpand) BOOL bExpand)
{ {
WCHAR ShortName[MAX_PATH]; WCHAR ShortName[MAX_PATH];
UNICODE_STRING Name; UNICODE_STRING Name;
UNICODE_STRING SrcValue; UNICODE_STRING SrcValue;
UNICODE_STRING DstValue; UNICODE_STRING DstValue;
ULONG Length; ULONG Length;
NTSTATUS Status; NTSTATUS Status;
PVOID Buffer=NULL;
if (bExpand) if (bExpand)
{ {
RtlInitUnicodeString(&SrcValue, RtlInitUnicodeString(&SrcValue,
lpValue); lpValue);
@ -50,43 +51,46 @@ SetUserEnvironmentVariable (LPVOID *Environment,
DstValue.Length = 0; DstValue.Length = 0;
DstValue.MaximumLength = Length; DstValue.MaximumLength = Length;
DstValue.Buffer = LocalAlloc(LPTR, DstValue.Buffer = Buffer = LocalAlloc(LPTR,
Length); Length);
if (DstValue.Buffer == NULL) if (DstValue.Buffer == NULL)
{ {
DPRINT1("LocalAlloc() failed\n"); DPRINT1("LocalAlloc() failed\n");
return FALSE; return FALSE;
} }
Status = RtlExpandEnvironmentStrings_U((PWSTR)*Environment, Status = RtlExpandEnvironmentStrings_U((PWSTR)*Environment,
&SrcValue, &SrcValue,
&DstValue, &DstValue,
&Length); &Length);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status); DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
DPRINT1("Length %lu\n", Length); DPRINT1("Length %lu\n", Length);
return FALSE; if (Buffer) LocalFree(Buffer);
} return FALSE;
} }
else }
{ else
{
RtlInitUnicodeString(&DstValue, RtlInitUnicodeString(&DstValue,
lpValue); lpValue);
} }
if (!_wcsicmp (lpName, L"temp") || !_wcsicmp (lpName, L"tmp")) if (!_wcsicmp (lpName, L"temp") || !_wcsicmp (lpName, L"tmp"))
{ {
if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH)) if (!GetShortPathNameW(DstValue.Buffer, ShortName, MAX_PATH))
{ {
DPRINT1("GetShortPathNameW() failed (Error %lu)\n", GetLastError()); DPRINT1("GetShortPathNameW() failed (Error %lu)\n", GetLastError());
return FALSE; if (Buffer) LocalFree(Buffer);
} return FALSE;
}
DPRINT("Buffer: %S\n", ShortName); DPRINT("Buffer: %S\n", ShortName);
RtlInitUnicodeString(&DstValue, RtlInitUnicodeString(&DstValue,
ShortName); ShortName);
} }
RtlInitUnicodeString(&Name, RtlInitUnicodeString(&Name,
lpName); lpName);
@ -97,10 +101,7 @@ SetUserEnvironmentVariable (LPVOID *Environment,
&Name, &Name,
&DstValue); &DstValue);
if (bExpand) if (Buffer) LocalFree(Buffer);
{
LocalFree(DstValue.Buffer);
}
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {