v icon indicating copy to clipboard operation
v copied to clipboard

_vcleanup crashes when importing `time` with -autofree

Open spiveeworks opened this issue 1 year ago • 1 comments

Describe the bug

When importing time and compiling with -autofree, if main returns, then during _vcleanup the program tries to call array_free on _const_time__long_days, which is a fixed sized array. This is an instance of #21211 but could be worked around in the mean time.

	array_free(&_const_time__long_days);

Reproduction Steps

import time

println("${time.now()}")

run with v -autofree run time_autofree_bug.v

Expected Behavior

I expect it to print the current time and then exit cleanly.

Current Behavior

It prints the current time, and then crashes.

2024-04-07 15:35:42
Unhandled Exception 0xC0000374
15: RtlIsZeroMemory            ?? : address = 0x23fa1d08350
14: RtlIsZeroMemory            ?? : address = 0x23fa1d08e40
13: RtlpNtSetValueKey          ?? : address = 0x23fa4b2d520
12: RtlpNtSetValueKey          ?? : address = 0x23fa4b2db60
11: RtlpNtSetValueKey          ?? : address = 0x23fa4b2e510
10: RtlGetCurrentServiceSessionId  ?? : address = 0x23fa4b2f320
9 : RtlFreeHeap                ?? : address = 0x23fa4b2edd0
8 : NotifyShims                ?? : address = 0x23fa4b2eba0
7 : free_base                  ?? : address = 0x23fa4b2fe60
6 : v_free                     ?? : address = 0x23fa4b30e00
5 : array_free                 ?? : address = 0x23fa4b312b0
4 : vcleanup                   ?? : address = 0x23fa4b42f60
3 : wmain                      ?? : address = 0x23fa4b431e0
2 : __scrt_common_main_seh     D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
1 : BaseThreadInitThunk        ?? : address = 0x23fa4b43e10
0 : RtlUserThreadStart         ?? : address = 0x23fa4b444a0

Possible Solution

_const_time__long_days is a Array_fixed_string_7, i.e. a [7]string, not a []string, and so cgen shouldn't be calling array_free on it.

Its definition is here: https://github.com/vlang/v/blob/master/vlib/time/time.v#L4

Looking at long_months in the same file, long_months is not declared with []!, possibly as a workaround to this same bug. In the short term making long_days not fixed-size would work around this problem, but fixing the actual bug itself: #21211 would solve it properly.

Additional Information/Context

Running on Windows with msvc.

V version

V 0.4.5 ad17be5

Environment details (OS name and version, etc.)

V full version: V 0.4.5 386bd77.ad17be5
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 4 cpus, 64bit, little endian,

getwd: C:\Users\Owner\Code\v-experiments
vexe: C:\Program Files\v\v.exe
vexe mtime: 2024-04-07 05:22:56

vroot: contains spaces, value: C:\Program Files\v
VMODULES: OK, value: C:\Users\Owner\.vmodules
VTMP: OK, value: C:\Users\Owner\AppData\Local\Temp\v_0

Git version: git version 2.37.2.windows.2
Git vroot status: 0.4.5-113-gad17be5d
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc: N/A

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

spiveeworks avatar Apr 07 '24 06:04 spiveeworks

I just tried it on Linux, and it seems to work:

#0 19:16:20 ^ master /v/oo>cat > a.v
import time

println("${time.now()}")
#0 19:20:29 ^ master /v/oo>v run a.v
2024-07-13 19:20:33
#0 19:20:33 ^ master /v/oo>v -autofree run a.v
2024-07-13 19:20:36
#0 19:20:36 ^ master /v/oo>v -os windows -autofree run a.v
Cross compiling for Windows...
/space/v/oo/a.exe has been successfully cross compiled for windows.
2024-07-13 19:21:01
#0 19:21:01 ^ master /v/oo>

I'll try on a windows with msvc asap too.

spytheman avatar Jul 13 '24 16:07 spytheman