Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 34 additions & 12 deletions versionfiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ if (! [string]::IsNullOrEmpty($BuildString)) {
$verBuildString += " `"-$BuildString`""
}

$contents=@"
$NtVerpContents=@"
#pragma once
//
// Generated file: DO NOT EDIT!
Expand Down Expand Up @@ -149,12 +149,17 @@ if (!(test-path -path $incPath)) {
$verpropfile = "$($incPath)\version.props"
$buildpropfile = "$($incPath)\buildnumber.props"
[bool] $createdMutex = $false
[bool] $mutexHeld = $false
$mutexName = ($incPath -replace "\\","-") -replace ":",""
$lock = new-object System.Threading.Mutex($false, $mutexName, [ref] $createdMutex);
$lock = new-object System.Threading.Mutex($true, $mutexName, [ref] $createdMutex);
Comment thread
HollisTech marked this conversation as resolved.
try {
$mutexHeld = $lock.WaitOne()
if (!$createdMutex) {
$lock.WaitOne()
log "mutex acquired after WaitOne."
} else {
log "created mutex $mutexName"
}
if ($generateProps -and !(test-path $verpropfile)) {
log "creating $verpropfile"
Comment thread
HollisTech marked this conversation as resolved.
$verprops | Set-Content $verpropfile
}
[string] $current = ""
Expand All @@ -164,26 +169,43 @@ try {
$current = $current.Trim()
}
}
$tempContents = $contents.Trim()
$tempContents = $NtVerpContents.Trim()
if (($current.Length -ne $tempContents.Length) -or ($current -cne $tempContents)) {
log "creating $($incPath)\ntverp.h"
$contents | set-content "$($incPath)\ntverp.h"
log "creating $($incPath)\ntverp.h current: $($current.Length) new: $($tempContents.Length)"
Remove-Item $incPath\ntverp.h -Force -ErrorAction SilentlyContinue
$tempContents | Set-Content "$($incPath)\ntverp.h" -Force
$current2 = (get-content "$($incPath)\ntverp.h" -raw)
if ($current2.Length) {
$current2 = $current2.Trim()
}
log "New $($incPath)\ntverp.h length $($current2.Length)"
if ($current2.Length -ne $tempContents.Length) {
log "Error truncated $($incPath)\ntverp.h now: $($current2.Length) tempContents: $($tempContents.Length)"
}
}
if (!(test-path $buildpropfile)) {
log "creating $buildpropfile"
$buildNumberProps | Set-Content $buildpropfile
} else {
log "updating $buildpropfile"
$buildNumberProps | Set-Content $buildpropfile -Force
$current = (get-content $buildpropfile -raw)
if ($current.Length) {
$current = $current.Trim()
}
$buildNumberProps = $buildNumberProps.Trim()
if (($current.Length -ne $buildNumberProps.Length) -or ($current -cne $buildNumberProps)) {
log "updating $buildpropfile"
$buildNumberProps | Set-Content $buildpropfile -Force
Comment thread
HollisTech marked this conversation as resolved.
}
}
$mutexHeld = $false
$lock.ReleaseMutex()
log "mutex released."
Comment on lines 200 to +201

Copilot AI Jan 15, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReleaseMutex() is called unconditionally in the try block but not protected in the finally block. If an exception occurs after successfully acquiring the mutex (lines 155-160), the mutex will be released in line 200 which won't be reached, then disposed in the finally block (line 208) without being released. This leaves the mutex in an abandoned state. Move the ReleaseMutex() call to the finally block before Dispose(), and guard it to only release if the mutex was actually acquired.

Copilot uses AI. Check for mistakes.
}
catch {
Write-Output $_ | Format-List * -Force | Out-String
Comment thread
HollisTech marked this conversation as resolved.
}
finally {
if ($mutexHeld) {
$lock.ReleaseMutex();
if ($lock) {
$lock.Dispose()
}
}
$verfile = "$incPath\version.h"
Expand Down
Loading