Project

General

Profile

Actions

Feature #1701

open

[proposed] resolved inconsistency in autoworker APIs to avoid memory handling errors

Added by John Robertson 20 days ago. Updated 9 days ago.

Status:
In Review
Priority:
Normal
Category:
AI
Target version:
Start date:
10/11/2025
Due date:
% Done:

0%

Estimated time:

Description

[3.3.90.6-dev]
#api_proposal

After experimenting with autoworkers, I ran into the following error, with a comment in gdb describing a double free of a pointer:

Program received signal SIGABRT, Aborted.
__pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
warning: 44     ./nptl/pthread_kill.c: No such file or directory
(gdb) bt
#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=<optimized out>) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007ffff764527e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007ffff76288ff in __GI_abort () at ./stdlib/abort.c:79
#5  0x00007ffff76297b6 in __libc_message_impl (fmt=fmt@entry=0x7ffff77ce8d7 "%s\n") at ../sysdeps/posix/libc_fatal.c:134
#6  0x00007ffff76a8ff5 in malloc_printerr (str=str@entry=0x7ffff77d1bf0 "free(): double free detected in tcache 2")
    at ./malloc/malloc.c:5772
#7  0x00007ffff76ab55f in _int_free (av=0x7ffff7803ac0 <main_arena>, p=<optimized out>, have_lock=0) at ./malloc/malloc.c:4541
#8  0x00007ffff76addae in __GI___libc_free (mem=0x555556f8ecc0) at ./malloc/malloc.c:3398

#9  0x00005555557e80d6 in pf_path_destroy (path=path@entry=0x55561a2b3230) at ../../../common/aicore/path_finding.c:3416

#10 0x00005555555a4a54 in auto_worker_findwork (nmap=<optimized out>, pplayer=pplayer@entry=0x555556fd1bb0, 
    punit=punit@entry=0x5556146927f0, state=state@entry=0x5555dfbbfc60, recursion=recursion@entry=0)
    at ../../../server/advisors/autoworkers.c:1153

#11 0x00005555555a5cdc in auto_workers_player (pplayer=pplayer@entry=0x555556fd1bb0) at ../../../server/advisors/autoworkers.c:1369
#12 0x00005555555753f9 in end_phase () at ../../server/srv_main.c:1524
#13 srv_running () at ../../server/srv_main.c:3025
#14 srv_main () at ../../server/srv_main.c:3606
#15 0x000055555556ad4e in main (argc=<optimized out>, argv=0x7fffffffdb88) at ../../server/srv_entrypoint.c:362
(gdb) 

Reviewing the offending code, I realized that my confusion was that two of the autoworker APIs worked differently than the third one.

Attached is a recommendation to make all three APIs work consistently with each other. I will take no offence if this issue is closed and rejected..


Files

1701.patch (6.81 KB) 1701.patch John Robertson, 10/11/2025 05:47 AM
1701.v2.patch (7.25 KB) 1701.v2.patch John Robertson, 10/11/2025 07:57 AM
1701.v3.patch (7.36 KB) 1701.v3.patch John Robertson, 10/17/2025 01:58 AM
Actions #1

Updated by John Robertson 20 days ago

Actions #2

Updated by John Robertson 19 days ago

(apologies, … I tend to catch a few more things after initial submission and review)

  • better function parameter name, for clarity
  • additional memory leak prevention checks
Actions #3

Updated by Marko Lindqvist 19 days ago

  • Category changed from Server to AI
  • Target version set to 3.4.0
Actions #4

Updated by Marko Lindqvist 19 days ago

The patch does not apply (to main branch). autoworkers.c has a conflict.

Actions #5

Updated by Marko Lindqvist 17 days ago

  • Tracker changed from Bug to Feature
Actions #6

Updated by John Robertson 14 days ago

updated and tested with recent pull

Actions #7

Updated by Marko Lindqvist 9 days ago

  • Status changed from New to In Review
  • Assignee set to Marko Lindqvist

Might take a while still before this gets merged, as I want to wait for the next autogame testing run and test this there first.

Actions

Also available in: Atom PDF