[USETUP] Sprinkle some INF_FreeData() calls to balance the INF_GetData() / INF_GetDataField() calls.

They currently do nothing, since the getter functions don't actually
capture (copy) the strings but merely return pointers to read-only strings.

But the calls are placed here for consistency, because if one day the
getters' implementation is changed so that strings are captured, it would
then be needed to free the allocated buffers.

In addition, fix a buggy call to INF_GetData() -- should be instead
INF_GetDataField() -- in AddSectionToCopyQueue().

svn path=/branches/setup_improvements/; revision=75516
This commit is contained in:
Hermès Bélusca-Maïto 2017-08-09 20:24:24 +00:00
parent aa110db3ea
commit cf2571de6e
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
3 changed files with 119 additions and 52 deletions

View file

@ -76,11 +76,17 @@ InstallDriver(
&& !SetupFindFirstLineW(hInf, L"InputDevicesSupport.Load", Driver, &Context) && !SetupFindFirstLineW(hInf, L"InputDevicesSupport.Load", Driver, &Context)
&& !SetupFindFirstLineW(hInf, L"Keyboard.Load", Driver, &Context)) && !SetupFindFirstLineW(hInf, L"Keyboard.Load", Driver, &Context))
{ {
INF_FreeData(ClassGuid);
INF_FreeData(Driver);
return FALSE; return FALSE;
} }
if (!INF_GetDataField(&Context, 1, &ImagePath)) if (!INF_GetDataField(&Context, 1, &ImagePath))
{
INF_FreeData(ClassGuid);
INF_FreeData(Driver);
return FALSE; return FALSE;
}
/* Prepare full driver path */ /* Prepare full driver path */
dwValue = PathPrefix.MaximumLength + wcslen(ImagePath) * sizeof(WCHAR); dwValue = PathPrefix.MaximumLength + wcslen(ImagePath) * sizeof(WCHAR);
@ -88,6 +94,9 @@ InstallDriver(
if (!FullImagePath) if (!FullImagePath)
{ {
DPRINT1("RtlAllocateHeap() failed\n"); DPRINT1("RtlAllocateHeap() failed\n");
INF_FreeData(ImagePath);
INF_FreeData(ClassGuid);
INF_FreeData(Driver);
return FALSE; return FALSE;
} }
RtlCopyMemory(FullImagePath, PathPrefix.Buffer, PathPrefix.MaximumLength); RtlCopyMemory(FullImagePath, PathPrefix.Buffer, PathPrefix.MaximumLength);
@ -103,6 +112,9 @@ InstallDriver(
{ {
DPRINT1("NtCreateKey('%wZ') failed with status 0x%08x\n", &StringU, Status); DPRINT1("NtCreateKey('%wZ') failed with status 0x%08x\n", &StringU, Status);
RtlFreeHeap(ProcessHeap, 0, FullImagePath); RtlFreeHeap(ProcessHeap, 0, FullImagePath);
INF_FreeData(ImagePath);
INF_FreeData(ClassGuid);
INF_FreeData(Driver);
return FALSE; return FALSE;
} }
@ -110,38 +122,38 @@ InstallDriver(
if (Disposition == REG_CREATED_NEW_KEY) if (Disposition == REG_CREATED_NEW_KEY)
{ {
dwValue = 0; dwValue = 0;
NtSetValueKey( NtSetValueKey(hService,
hService, &ErrorControlU,
&ErrorControlU, 0,
0, REG_DWORD,
REG_DWORD, &dwValue,
&dwValue, sizeof(dwValue));
sizeof(dwValue));
dwValue = 0; dwValue = 0;
NtSetValueKey( NtSetValueKey(hService,
hService, &StartU,
&StartU, 0,
0, REG_DWORD,
REG_DWORD, &dwValue,
&dwValue, sizeof(dwValue));
sizeof(dwValue));
dwValue = SERVICE_KERNEL_DRIVER; dwValue = SERVICE_KERNEL_DRIVER;
NtSetValueKey( NtSetValueKey(hService,
hService, &TypeU,
&TypeU, 0,
0, REG_DWORD,
REG_DWORD, &dwValue,
&dwValue, sizeof(dwValue));
sizeof(dwValue));
} }
/* HACK: don't put any path in registry */ /* HACK: don't put any path in registry */
NtSetValueKey( NtSetValueKey(hService,
hService, &ImagePathU,
&ImagePathU, 0,
0, REG_SZ,
REG_SZ, ImagePath,
ImagePath, (wcslen(ImagePath) + 1) * sizeof(WCHAR));
(wcslen(ImagePath) + 1) * sizeof(WCHAR));
INF_FreeData(ImagePath);
if (ClassGuid &&_wcsicmp(ClassGuid, L"{4D36E96B-E325-11CE-BFC1-08002BE10318}") == 0) if (ClassGuid &&_wcsicmp(ClassGuid, L"{4D36E96B-E325-11CE-BFC1-08002BE10318}") == 0)
{ {
@ -154,29 +166,32 @@ InstallDriver(
(wcslen(keyboardClass) + 2) * sizeof(WCHAR)); (wcslen(keyboardClass) + 2) * sizeof(WCHAR));
} }
INF_FreeData(ClassGuid);
/* Associate device with the service we just filled */ /* Associate device with the service we just filled */
Status = NtSetValueKey( Status = NtSetValueKey(hDeviceKey,
hDeviceKey, &ServiceU,
&ServiceU, 0,
0, REG_SZ,
REG_SZ, Driver,
Driver, (wcslen(Driver) + 1) * sizeof(WCHAR));
(wcslen(Driver) + 1) * sizeof(WCHAR));
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* Restart the device, so it will use the driver we registered */ /* Restart the device, so it will use the driver we registered */
deviceInstalled = ResetDevice(DeviceId); deviceInstalled = ResetDevice(DeviceId);
} }
INF_FreeData(Driver);
/* HACK: Update driver path */ /* HACK: Update driver path */
NtSetValueKey( NtSetValueKey(hService,
hService, &ImagePathU,
&ImagePathU, 0,
0, REG_SZ,
REG_SZ, FullImagePath,
FullImagePath, (wcslen(FullImagePath) + 1) * sizeof(WCHAR));
(wcslen(FullImagePath) + 1) * sizeof(WCHAR));
RtlFreeHeap(ProcessHeap, 0, FullImagePath); RtlFreeHeap(ProcessHeap, 0, FullImagePath);
NtClose(hService); NtClose(hService);
return deviceInstalled; return deviceInstalled;

View file

@ -324,6 +324,7 @@ CreateComputerTypeList(
DPRINT("KeyValue: %S\n", KeyValue); DPRINT("KeyValue: %S\n", KeyValue);
if (wcsstr(ComputerIdentifier, KeyValue)) if (wcsstr(ComputerIdentifier, KeyValue))
{ {
INF_FreeData(KeyValue);
if (!INF_GetDataField(&Context, 0, &KeyName)) if (!INF_GetDataField(&Context, 0, &KeyName))
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
@ -333,7 +334,9 @@ CreateComputerTypeList(
DPRINT("Computer key: %S\n", KeyName); DPRINT("Computer key: %S\n", KeyName);
wcscpy(ComputerKey, KeyName); wcscpy(ComputerKey, KeyName);
INF_FreeData(KeyName);
} }
INF_FreeData(KeyValue);
} while (SetupFindNextLine(&Context, &Context)); } while (SetupFindNextLine(&Context, &Context));
List = CreateGenericList(); List = CreateGenericList();
@ -348,7 +351,7 @@ CreateComputerTypeList(
do do
{ {
if (!INF_GetData (&Context, &KeyName, &KeyValue)) if (!INF_GetData(&Context, &KeyName, &KeyValue))
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT("INF_GetData() failed\n"); DPRINT("INF_GetData() failed\n");
@ -364,10 +367,13 @@ CreateComputerTypeList(
} }
wcscpy(UserData, KeyName); wcscpy(UserData, KeyName);
INF_FreeData(KeyName);
sprintf(Buffer, "%S", KeyValue); sprintf(Buffer, "%S", KeyValue);
INF_FreeData(KeyValue);
AppendGenericListEntry(List, Buffer, UserData, AppendGenericListEntry(List, Buffer, UserData,
_wcsicmp(KeyName, ComputerKey) ? FALSE : TRUE); _wcsicmp(UserData, ComputerKey) ? FALSE : TRUE);
} while (SetupFindNextLine(&Context, &Context)); } while (SetupFindNextLine(&Context, &Context));
return List; return List;
@ -579,6 +585,7 @@ CreateDisplayDriverList(
DPRINT("KeyValue: %S\n", KeyValue); DPRINT("KeyValue: %S\n", KeyValue);
if (wcsstr(DisplayIdentifier, KeyValue)) if (wcsstr(DisplayIdentifier, KeyValue))
{ {
INF_FreeData(KeyValue);
if (!INF_GetDataField(&Context, 0, &KeyName)) if (!INF_GetDataField(&Context, 0, &KeyName))
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
@ -588,7 +595,9 @@ CreateDisplayDriverList(
DPRINT("Display key: %S\n", KeyName); DPRINT("Display key: %S\n", KeyName);
wcscpy(DisplayKey, KeyName); wcscpy(DisplayKey, KeyName);
INF_FreeData(KeyName);
} }
INF_FreeData(KeyValue);
} while (SetupFindNextLine(&Context, &Context)); } while (SetupFindNextLine(&Context, &Context));
List = CreateGenericList(); List = CreateGenericList();
@ -612,6 +621,7 @@ CreateDisplayDriverList(
if (!INF_GetDataField(&Context, 1, &KeyValue)) if (!INF_GetDataField(&Context, 1, &KeyValue))
{ {
DPRINT1("INF_GetDataField() failed\n"); DPRINT1("INF_GetDataField() failed\n");
INF_FreeData(KeyName);
break; break;
} }
@ -622,16 +632,19 @@ CreateDisplayDriverList(
{ {
DPRINT1("RtlAllocateHeap() failed\n"); DPRINT1("RtlAllocateHeap() failed\n");
DestroyGenericList(List, TRUE); DestroyGenericList(List, TRUE);
INF_FreeData(KeyValue);
INF_FreeData(KeyName);
return NULL; return NULL;
} }
wcscpy(UserData, KeyName); wcscpy(UserData, KeyName);
INF_FreeData(KeyName);
sprintf(Buffer, "%S", KeyValue); sprintf(Buffer, "%S", KeyValue);
AppendGenericListEntry(List, INF_FreeData(KeyValue);
Buffer,
UserData, AppendGenericListEntry(List, Buffer, UserData,
_wcsicmp(KeyName, DisplayKey) ? FALSE : TRUE); _wcsicmp(UserData, DisplayKey) ? FALSE : TRUE);
} while (SetupFindNextLine(&Context, &Context)); } while (SetupFindNextLine(&Context, &Context));
#if 0 #if 0
@ -1061,7 +1074,7 @@ CreateLanguageList(
} while (SetupFindNextLine(&Context, &Context)); } while (SetupFindNextLine(&Context, &Context));
/* Only one language available, make it the default one */ /* Only one language available, make it the default one */
if(uIndex == 1 && UserData != NULL) if (uIndex == 1 && UserData != NULL)
{ {
DefaultLanguageIndex = 0; DefaultLanguageIndex = 0;
wcscpy(DefaultLanguage, UserData); wcscpy(DefaultLanguage, UserData);
@ -1234,7 +1247,7 @@ SetGeoID(
Status = NtOpenKey(&KeyHandle, Status = NtOpenKey(&KeyHandle,
KEY_SET_VALUE, KEY_SET_VALUE,
&ObjectAttributes); &ObjectAttributes);
if(!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); DPRINT1("NtOpenKey() failed (Status %lx)\n", Status);
return FALSE; return FALSE;

View file

@ -3718,13 +3718,20 @@ AddSectionToCopyQueueCab(HINF InfFile,
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("SetupFindFirstLine() failed\n"); DPRINT1("SetupFindFirstLine() failed\n");
INF_FreeData(FileKeyName);
INF_FreeData(FileKeyValue);
INF_FreeData(TargetFileName);
break; break;
} }
INF_FreeData(FileKeyValue);
if (!INF_GetData(&DirContext, NULL, &DirKeyValue)) if (!INF_GetData(&DirContext, NULL, &DirKeyValue))
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("INF_GetData() failed\n"); DPRINT1("INF_GetData() failed\n");
INF_FreeData(FileKeyName);
INF_FreeData(TargetFileName);
break; break;
} }
@ -3739,6 +3746,10 @@ AddSectionToCopyQueueCab(HINF InfFile,
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("SetupQueueCopy() failed\n"); DPRINT1("SetupQueueCopy() failed\n");
} }
INF_FreeData(FileKeyName);
INF_FreeData(TargetFileName);
INF_FreeData(DirKeyValue);
} while (SetupFindNextLine(&FilesContext, &FilesContext)); } while (SetupFindNextLine(&FilesContext, &FilesContext));
return TRUE; return TRUE;
@ -3782,8 +3793,8 @@ AddSectionToCopyQueue(HINF InfFile,
*/ */
do do
{ {
/* Get source file name and target directory id */ /* Get source file name */
if (!INF_GetData(&FilesContext, &FileKeyName, &FileKeyValue)) if (!INF_GetDataField(&FilesContext, 0, &FileKeyName))
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("INF_GetData() failed\n"); DPRINT1("INF_GetData() failed\n");
@ -3795,6 +3806,7 @@ AddSectionToCopyQueue(HINF InfFile,
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("INF_GetData() failed\n"); DPRINT1("INF_GetData() failed\n");
INF_FreeData(FileKeyName);
break; break;
} }
@ -3811,13 +3823,20 @@ AddSectionToCopyQueue(HINF InfFile,
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("SetupFindFirstLine() failed\n"); DPRINT1("SetupFindFirstLine() failed\n");
INF_FreeData(FileKeyName);
INF_FreeData(FileKeyValue);
INF_FreeData(TargetFileName);
break; break;
} }
INF_FreeData(FileKeyValue);
if (!INF_GetData(&DirContext, NULL, &DirKeyValue)) if (!INF_GetData(&DirContext, NULL, &DirKeyValue))
{ {
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("INF_GetData() failed\n"); DPRINT1("INF_GetData() failed\n");
INF_FreeData(FileKeyName);
INF_FreeData(TargetFileName);
break; break;
} }
@ -3863,6 +3882,10 @@ AddSectionToCopyQueue(HINF InfFile,
/* FIXME: Handle error! */ /* FIXME: Handle error! */
DPRINT1("SetupQueueCopy() failed\n"); DPRINT1("SetupQueueCopy() failed\n");
} }
INF_FreeData(FileKeyName);
INF_FreeData(TargetFileName);
INF_FreeData(DirKeyValue);
} while (SetupFindNextLine(&FilesContext, &FilesContext)); } while (SetupFindNextLine(&FilesContext, &FilesContext));
return TRUE; return TRUE;
@ -3968,6 +3991,7 @@ PrepareCopyPageInfFile(HINF InfFile,
Status = SetupCreateDirectory(PathBuffer); Status = SetupCreateDirectory(PathBuffer);
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION) if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION)
{ {
INF_FreeData(DirKeyValue);
DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status); DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status);
MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER); MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER);
return FALSE; return FALSE;
@ -3986,11 +4010,14 @@ PrepareCopyPageInfFile(HINF InfFile,
Status = SetupCreateDirectory(PathBuffer); Status = SetupCreateDirectory(PathBuffer);
if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION) if (!NT_SUCCESS(Status) && Status != STATUS_OBJECT_NAME_COLLISION)
{ {
INF_FreeData(DirKeyValue);
DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status); DPRINT("Creating directory '%S' failed: Status = 0x%08lx", PathBuffer, Status);
MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER); MUIDisplayError(ERROR_CREATE_DIR, Ir, POPUP_WAIT_ENTER);
return FALSE; return FALSE;
} }
} }
INF_FreeData(DirKeyValue);
} while (SetupFindNextLine(&DirContext, &DirContext)); } while (SetupFindNextLine(&DirContext, &DirContext));
return TRUE; return TRUE;
@ -4380,7 +4407,12 @@ DoUpdate:
DPRINT("Action: %S File: %S Section %S\n", Action, File, Section); DPRINT("Action: %S File: %S Section %S\n", Action, File, Section);
if (Action == NULL) if (Action == NULL)
{
INF_FreeData(Action);
INF_FreeData(File);
INF_FreeData(Section);
break; // Hackfix break; // Hackfix
}
if (!_wcsicmp(Action, L"AddReg")) if (!_wcsicmp(Action, L"AddReg"))
Delete = FALSE; Delete = FALSE;
@ -4389,14 +4421,21 @@ DoUpdate:
else else
{ {
DPRINT1("Unrecognized registry INF action '%S'\n", Action); DPRINT1("Unrecognized registry INF action '%S'\n", Action);
INF_FreeData(Action);
INF_FreeData(File);
INF_FreeData(Section);
continue; continue;
} }
INF_FreeData(Action);
CONSOLE_SetStatusText(MUIGetString(STRING_IMPORTFILE), File); CONSOLE_SetStatusText(MUIGetString(STRING_IMPORTFILE), File);
if (!ImportRegistryFile(SourcePath.Buffer, File, Section, LanguageId, Delete)) if (!ImportRegistryFile(SourcePath.Buffer, File, Section, LanguageId, Delete))
{ {
DPRINT1("Importing %S failed\n", File); DPRINT1("Importing %S failed\n", File);
INF_FreeData(File);
INF_FreeData(Section);
MUIDisplayError(ERROR_IMPORT_HIVE, Ir, POPUP_WAIT_ENTER); MUIDisplayError(ERROR_IMPORT_HIVE, Ir, POPUP_WAIT_ENTER);
goto Cleanup; goto Cleanup;
} }