New Issue: segmentation fault when seeking a channel

18919, "jhh67", "segmentation fault when seeking a channel", "2022-01-05T23:33:57Z"

Summary of Problem

My program suffered a segmentation fault when seeking a channel back to offset 0. The information below is from a Mac running MacOS 10.15.7, but I also confirmed that it fails on chapcs.

Steps to Reproduce

Source Code:

use IO;

config var input: string;

var fp = open(input, iomode.r);
var ch = fp.reader(locking=false);

var value: string;

while(ch.read(value)) {
}

ch.seek(0);

Compile command:

chpl foo.chpl

Execution command:

./foo --input foo.input

Any non-empty input file will cause the problem, e.g.

x

Associated Future Test(s):

Configuration Information

  • Output of chpl --version:
chpl version 1.26.0 pre-release (2068b23762)
Copyright 2020-2021 Hewlett Packard Enterprise Development LP
Copyright 2004-2019 Cray Inc.
(See LICENSE file for more details)
  • Output of $CHPL_HOME/util/printchplenv --anonymize:
CHPL_TARGET_PLATFORM: darwin
CHPL_TARGET_COMPILER: clang
CHPL_TARGET_ARCH: x86_64
CHPL_TARGET_CPU: native
CHPL_LOCALE_MODEL: flat
CHPL_COMM: none *
CHPL_TASKS: qthreads
CHPL_LAUNCHER: none
CHPL_TIMERS: generic
CHPL_UNWIND: none
CHPL_MEM: jemalloc
CHPL_ATOMICS: cstdlib
CHPL_GMP: none *
CHPL_HWLOC: bundled
CHPL_RE2: bundled
CHPL_LLVM: none *
CHPL_AUX_FILESYS: none
  • Back-end compiler and version, e.g. gcc --version or clang --version:
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
  • Debugging info
(lldb) bt
* thread #2, stop reason = signal SIGSTOP
  * frame #0: 0x0000000106ecff66 foo`qbytes_release(qb=0x0000000107614090) at qbuffer.h:150:3
    frame #1: 0x0000000106ed0f65 foo`qbuffer_trim_back(buf=0x000000010760d670, remove_bytes=131071) at qbuffer.c:550:9
    frame #2: 0x0000000106ee0484 foo`qio_channel_seek(ch=0x000000010760d600, start=0, end=9223372036854775807) at qio.c:3929:5
    frame #3: 0x0000000106ead1ad foo`seek_chpl + 221
    frame #4: 0x0000000106e7c40e foo`chpl__init_foo + 5806
    frame #5: 0x0000000106e7ac5c foo`chpl_gen_main + 76
    frame #6: 0x0000000106ec49c5 foo`chpl_executable_init at chpl-init.c:321:38
    frame #7: 0x0000000106eca562 foo`chapel_wrapper(arg=0x000000010744e040) at tasks-qthreads.c:740:5
    frame #8: 0x0000000106f2e79d foo`qthread_wrapper(ptr=0x000000010744e000) at qthread.c:2175:32

(lldb) frame select 0
frame #0: 0x0000000106ecff66 foo`qbytes_release(qb=0x0000000107614090) at qbuffer.h:150:3
   147   static inline
   148   void qbytes_release(qbytes_t* qb)
   149   {
-> 150     DO_RELEASE(qb, qb->free_function);
   151   }
   152
   153   // for being called by free functions... frees only the qbytes itself.

(lldb) p qb->free_function
(qbytes_free_t) $0 = 0x0000000000000000