{"action":"closed","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/2478","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/2478/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/2478/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/2478/events","html_url":"https://github.com/dotnet/coreclr/issues/2478","id":124148813,"number":2478,"title":"A finalizer is run for an object that was not constructed and should not have been allocated","user":{"login":"rationull","id":6431686,"avatar_url":"https://avatars.githubusercontent.com/u/6431686?v=3","gravatar_id":"","url":"https://api.github.com/users/rationull","html_url":"https://github.com/rationull","followers_url":"https://api.github.com/users/rationull/followers","following_url":"https://api.github.com/users/rationull/following{/other_user}","gists_url":"https://api.github.com/users/rationull/gists{/gist_id}","starred_url":"https://api.github.com/users/rationull/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rationull/subscriptions","organizations_url":"https://api.github.com/users/rationull/orgs","repos_url":"https://api.github.com/users/rationull/repos","events_url":"https://api.github.com/users/rationull/events{/privacy}","received_events_url":"https://api.github.com/users/rationull/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/coreclr/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/coreclr/labels/CodeGen","name":"CodeGen","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":{"login":"hoyMS","id":15899383,"avatar_url":"https://avatars.githubusercontent.com/u/15899383?v=3","gravatar_id":"","url":"https://api.github.com/users/hoyMS","html_url":"https://github.com/hoyMS","followers_url":"https://api.github.com/users/hoyMS/followers","following_url":"https://api.github.com/users/hoyMS/following{/other_user}","gists_url":"https://api.github.com/users/hoyMS/gists{/gist_id}","starred_url":"https://api.github.com/users/hoyMS/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hoyMS/subscriptions","organizations_url":"https://api.github.com/users/hoyMS/orgs","repos_url":"https://api.github.com/users/hoyMS/repos","events_url":"https://api.github.com/users/hoyMS/events{/privacy}","received_events_url":"https://api.github.com/users/hoyMS/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/dotnet/coreclr/milestones/4","html_url":"https://github.com/dotnet/coreclr/milestones/1.0.0-rtm","labels_url":"https://api.github.com/repos/dotnet/coreclr/milestones/4/labels","id":1321405,"number":4,"title":"1.0.0-rtm","description":"Q1 2016 (https://github.com/dotnet/corefx/milestones)","creator":{"login":"joshfree","id":1302850,"avatar_url":"https://avatars.githubusercontent.com/u/1302850?v=3","gravatar_id":"","url":"https://api.github.com/users/joshfree","html_url":"https://github.com/joshfree","followers_url":"https://api.github.com/users/joshfree/followers","following_url":"https://api.github.com/users/joshfree/following{/other_user}","gists_url":"https://api.github.com/users/joshfree/gists{/gist_id}","starred_url":"https://api.github.com/users/joshfree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/joshfree/subscriptions","organizations_url":"https://api.github.com/users/joshfree/orgs","repos_url":"https://api.github.com/users/joshfree/repos","events_url":"https://api.github.com/users/joshfree/events{/privacy}","received_events_url":"https://api.github.com/users/joshfree/received_events","type":"User","site_admin":false},"open_issues":108,"closed_issues":35,"state":"open","created_at":"2015-09-24T02:23:52Z","updated_at":"2016-02-12T01:39:27Z","due_on":"2016-03-31T07:00:00Z","closed_at":null},"comments":6,"created_at":"2015-12-29T01:32:58Z","updated_at":"2016-02-12T01:39:27Z","closed_at":"2016-02-12T01:39:27Z","body":"I'm logging this here because it seems most likely to be a bug in JIT compilation or optimization. If you conclude that this should instead be posted against a component in Microsoft Connect then please comment as such and I will resubmit there.\r\n\r\nI have a C++/CLI function that contains a function call followed by an object allocation (an instance of a class implemented in C# in a separate assembly). In some cases, the function call is (by design) interrupted by an exception, which should preempt the object allocation. (Exception thrown out of BuildContent() in the provided code, such that the ViewerWindow instance should not be allocated).\r\n\r\nWhen I run a Release build without a debugger attached, and execute this case, then when garbage collection runs a ViewerWindow finalizer runs despite the fact that no ViewerWindow should have been created, and no ViewerWindow constructor has run. I can verify that that the finalizer ran and the constructor did not via trace output in the finalizer and constructor. Running attached to the debugger (or running a Debug build) does not exhibit this behavior.\r\n\r\nIf I attach a debugger after the exception is thrown, I can obtain an assembly dump of the affected function in the state that produces the extra finalizer call. Note that the disassembly visibly differs based on whether the debugger was attached at process launch or whether I attached the debugger after the exception that should interrupt the function.\r\n\r\nUnfortunately I have not yet been able to construct a minimal repro project, and I cannot provide full context from my repro case since it's part of a large proprietary application. However, I have created some sanitized dumps of the affected function in various states of compilation, and stored them in a github repo: https://github.com/rationull/JITFinalizerProblem\r\n\r\n\r\nHopefully this can provide enough of a clue as to what might be going on. The repo includes dumps of the original code, generated MSIL code from a Release build, and disassemblies from the debugger for both the repro and no-repro cases. See README.md in that repo for details.\r\n\r\nPlease let me know if there's any other information I can glean from my own repro that will help in the absence of a shareable project."}}