Commit 50f3dd8
committed
libretro-common/queues: add task_free_error + document set/free protocol
task_set_title() and task_set_error() take ownership of a heap
pointer and rely on the task system to free it at completion, but
neither setter frees the *previous* value -- so calling either one
twice on the same task without an intervening free leaks the prior
string. task_free_title() has long existed for the title side of
this protocol; the error side had no symmetric helper at all,
forcing callers that legitimately needed to update the error mid-
task to either guard with task_get_error() or just live with the
leak.
This commit:
* Adds task_free_error(), symmetric to the pre-existing
task_free_title() (both lock property_lock under HAVE_THREADS,
free if non-NULL, NULL out the field).
* Documents the free-then-set protocol clearly in
queues/task_queue.h on both setters, both struct fields, and
cross-references the helpers via @see -- the previous "@warning
This does not free the existing X" line was correct but easy to
miss, and three sites in tasks/task_cloudsync.c missed it.
* Fixes those three task_cloudsync.c violators (lines 107, 1281,
1331). task_cloudsync sets the initial title at line 1439 via
direct assignment, then later replaces it via task_set_title in
three callbacks without calling task_free_title first. Each
replacement leaks the prior strdup.
* Adds a regression test under libretro-common/samples/queues/
task_queue_title_error_test/ exercising both helpers and the
free-then-set protocol (single-set, replace-via-free, free-on-
null no-op, double-free no-op, 50-iteration stress chain).
Wires it into the existing libretro-common-samples CI workflow,
so it builds under -fsanitize=address,undefined and LSan flags
any future regression to the protocol.
The test compiles task_queue.c without HAVE_THREADS so the slock /
scond / sthread paths drop out cleanly -- the title/error
protocol is identical with and without threading; the locks just
serialise it. The single remaining external dependency
(cpu_features_get_time_usec) is provided as a trivial stub since
no test path drives the queue through gather().
Verified pre-patch: the test fails to link without task_free_error
(undefined reference), confirming it genuinely exercises the new
symbol rather than passing trivially.
Verified post-patch: ASan + UBSan + LSan clean, all ten cases
pass.1 parent a0d08c1 commit 50f3dd8
6 files changed
Lines changed: 506 additions & 5 deletions
File tree
- .github/workflows
- libretro-common
- include/queues
- queues
- samples/queues/task_queue_title_error_test
- tasks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
212 | 217 | | |
| 218 | + | |
213 | 219 | | |
214 | 220 | | |
215 | 221 | | |
| |||
230 | 236 | | |
231 | 237 | | |
232 | 238 | | |
233 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
234 | 244 | | |
| 245 | + | |
| 246 | + | |
235 | 247 | | |
236 | 248 | | |
237 | 249 | | |
| |||
413 | 425 | | |
414 | 426 | | |
415 | 427 | | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
416 | 444 | | |
417 | 445 | | |
418 | 446 | | |
419 | 447 | | |
420 | | - | |
421 | | - | |
| 448 | + | |
422 | 449 | | |
423 | 450 | | |
424 | 451 | | |
| |||
437 | 464 | | |
438 | 465 | | |
439 | 466 | | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
440 | 481 | | |
441 | 482 | | |
442 | 483 | | |
443 | 484 | | |
444 | 485 | | |
445 | | - | |
446 | | - | |
447 | 486 | | |
448 | 487 | | |
449 | 488 | | |
| |||
467 | 506 | | |
468 | 507 | | |
469 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
470 | 518 | | |
471 | 519 | | |
472 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1023 | 1023 | | |
1024 | 1024 | | |
1025 | 1025 | | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
1026 | 1039 | | |
1027 | 1040 | | |
1028 | 1041 | | |
| |||
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
0 commit comments