Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pipeName be WideCStringObj so the data isn't deleted too early #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ire4ever1190
Copy link
Contributor

Issue was brought up with nimlsp CI failing on windows

Investigating it led me to this section where pipeName was becoming garbage by the time it got to line 186. Looking at the arc expansion I saw the internal data was getting deleted too early

try:
  var number = 0'i64
  var pipeName: WideCString
  var pipeIn: Handle
  var pipeOut: Handle
  var sa = SECURITY_ATTRIBUTES(nLength: 24, lpSecurityDescriptor: nil,
                               bInheritHandle: 1)
  echo ["start loop"]
  block :tmp:
    while true:
      var
        p
        :tmpD_1
        :tmpD_2
      try:
        QueryPerformanceCounter(number)
        p = `&`(r"\\.\pipe\asyncpipe_") do:
          :tmpD_1 = $number
          :tmpD_1
        # Converter is called here which returns the raw data stored
        pipeName = toWideCString(
          :tmpD_2 = newWideCString(p)
          :tmpD_2)
        var openMode = 1074266113'i32
        var pipeMode = 0'i32
        pipeIn = createNamedPipe(pipeName, openMode, pipeMode, 1'i32, 65536'i32,
                                 65536'i32, 1'i32, addr(sa))
        if pipeIn == -1:
          let err = osLastError()
          if (
            not (int32(err) == 231)):
            raiseOSError(err, "")
        else:
          break :tmp
      finally:
        # Destroys the object which deallocs the data which
        # we are still using the pointer to
        `=destroy_1`(:tmpD_2)
        `=destroy`(:tmpD_1)
        `=destroy`(p)
  var openMode_1 = 1048578'i32

By keeping a reference to the actual object instead of the pointer inside, it doesn't get destroyed too early

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant