reactos/lib/userenv
diff -u -r1.8 -r1.9
--- environment.c 10 Oct 2004 18:26:33 -0000 1.8
+++ environment.c 30 Nov 2004 02:26:25 -0000 1.9
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* 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
* PROJECT: ReactOS system libraries
@@ -34,15 +34,16 @@
LPWSTR lpValue,
BOOL bExpand)
{
- WCHAR ShortName[MAX_PATH];
- UNICODE_STRING Name;
- UNICODE_STRING SrcValue;
- UNICODE_STRING DstValue;
- ULONG Length;
- NTSTATUS Status;
+ WCHAR ShortName[MAX_PATH];
+ UNICODE_STRING Name;
+ UNICODE_STRING SrcValue;
+ UNICODE_STRING DstValue;
+ ULONG Length;
+ NTSTATUS Status;
+ PVOID Buffer=NULL;
- if (bExpand)
- {
+ if (bExpand)
+ {
RtlInitUnicodeString(&SrcValue,
lpValue);
@@ -50,43 +51,46 @@
DstValue.Length = 0;
DstValue.MaximumLength = Length;
- DstValue.Buffer = LocalAlloc(LPTR,
- Length);
+ DstValue.Buffer = Buffer = LocalAlloc(LPTR,
+ Length);
+
if (DstValue.Buffer == NULL)
- {
- DPRINT1("LocalAlloc() failed\n");
- return FALSE;
- }
+ {
+ DPRINT1("LocalAlloc() failed\n");
+ return FALSE;
+ }
Status = RtlExpandEnvironmentStrings_U((PWSTR)*Environment,
&SrcValue,
&DstValue,
&Length);
if (!NT_SUCCESS(Status))
- {
- DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
- DPRINT1("Length %lu\n", Length);
- return FALSE;
- }
- }
- else
- {
+ {
+ DPRINT1("RtlExpandEnvironmentStrings_U() failed (Status %lx)\n", Status);
+ DPRINT1("Length %lu\n", Length);
+ if (Buffer) LocalFree(Buffer);
+ return FALSE;
+ }
+ }
+ else
+ {
RtlInitUnicodeString(&DstValue,
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))
- {
- DPRINT1("GetShortPathNameW() failed (Error %lu)\n", GetLastError());
- return FALSE;
- }
+ {
+ DPRINT1("GetShortPathNameW() failed (Error %lu)\n", GetLastError());
+ if (Buffer) LocalFree(Buffer);
+ return FALSE;
+ }
DPRINT("Buffer: %S\n", ShortName);
RtlInitUnicodeString(&DstValue,
ShortName);
- }
+ }
RtlInitUnicodeString(&Name,
lpName);
@@ -97,11 +101,8 @@
&Name,
&DstValue);
- if (bExpand)
- {
- LocalFree(DstValue.Buffer);
- }
-
+ if (Buffer) LocalFree(Buffer);
+
if (!NT_SUCCESS(Status))
{
DPRINT1("RtlSetEnvironmentVariable() failed (Status %lx)\n", Status);