Skip to content

double free bug with arc, Result type, object refs, and iterators #13102

Closed
@disruptek

Description

@disruptek

This is my current repro:

type
  D = ref object
  R = object
    case o: bool
    of true:
      d: D
    of false:
      discard

proc get(r: R): D =
  result = r.d

iterator things(): R =
  while true:
    yield R(o: true, d: D())

for n in things():
  when defined(crashme):
    discard n.get
  once:
    continue
  break

The crashme branch is on the left:

  //      yield R.ok D(x: i)
  					eqsink___Vxyc5ibyvJXAnSDCKVo0QQ((&n__T1vjwqUZuuW0aWoZZsYHsQ), T5_);
  //  discard n.unsafeGet.x
  					(void)((*n__T1vjwqUZuuW0aWoZZsYHsQ.v).x);
- //    discard n.get.x
- //      yield R.ok D(x: i)
- //    discard n.get.x
- //    discard n.get.x
- 					T7_ = (tyObject_DcolonObjectType___6TuBWP49bfEosJ8P1C7T4bw*)0;
- 					T7_ = get__dyNOqu4hmuyhepcGsIdpBwresults(n__T1vjwqUZuuW0aWoZZsYHsQ);
- //      yield R.ok D(x: i)
- 					eqsink___ZjaqRTgzdDygyGf9cxywHtA(&colontmpD__2, T7_);
- 					(void)((*colontmpD__2).x);
  //        inc(res)
  					res += ((NI) 1);
  				} LA4: ;
  			}
  		}
  	}
- //      yield R.ok D(x: i)
- //      yield R.ok D(x: i)
- 	eqdestroy___xadGWVQE8F8qfCUpBt9cTkg(&colontmpD__2);

So it seems like we're sinking the same ref twice, which makes me think that
maybe we're missing a move, right?

-d:traceArc is super helpful.

This could be a separate issue; probably not a problem if the first issue is fixed.

type
  D = ref object
  R = object
    case o: bool
    of true:
      d: D
    of false:
      discard

iterator things(): R =
  when defined(crashme):
    var
      x = D()
  while true:
    when not defined(crashme):
      var
        x = D()
    yield R(o: true, d: x)

for n in things():
  when defined(crashme):
    discard n.d
  once:
    continue
  break

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions