[NTFS]
authorPierre Schweitzer <pierre@reactos.org>
Wed, 13 Apr 2016 19:52:42 +0000 (19:52 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Wed, 13 Apr 2016 19:52:42 +0000 (19:52 +0000)
Don't leak memory in case of failures in NtfsReadDisk().

Based on a patch by Trevor Thompson.

CORE-10998

svn path=/trunk/; revision=71155

reactos/drivers/filesystems/ntfs/blockdev.c

index ed1d642..6c90131 100644 (file)
@@ -87,6 +87,12 @@ NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
     if (Irp == NULL)
     {
         DPRINT("IoBuildSynchronousFsdRequest failed\n");
+
+        if (AllocatedBuffer)
+        {
+            ExFreePoolWithTag(ReadBuffer, TAG_NTFS);
+        }
+
         return STATUS_INSUFFICIENT_RESOURCES;
     }
 
@@ -108,9 +114,13 @@ NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
         Status = IoStatus.Status;
     }
 
-    if (NT_SUCCESS(Status) && AllocatedBuffer)
+    if (AllocatedBuffer)
     {
-        RtlCopyMemory(Buffer, ReadBuffer + (StartingOffset - RealReadOffset), Length);
+        if (NT_SUCCESS(Status))
+        {
+            RtlCopyMemory(Buffer, ReadBuffer + (StartingOffset - RealReadOffset), Length);
+        }
+
         ExFreePoolWithTag(ReadBuffer, TAG_NTFS);
     }