Commit 05de9cb
committed
gfx/sixel,network: reuse menu frame buffer across set_texture_frame calls
Both drivers unconditionally free'd menu_frame and set it to NULL
before a subsequent size-comparison check, making the "only reallocate
if size changed" branch dead. Every menu frame triggered a full
free+malloc+memcpy round-trip on a buffer that typically never changes
size after the first call.
Replace with a cached-capacity realloc pattern: allocate or grow only
when the required size exceeds the current capacity; otherwise reuse
the existing buffer. On realloc failure the previous frame is kept
intact (the original free+malloc sequence would have lost it).
These drivers store their menu state in file-scope static globals
rather than struct members (unlike e.g. fpga/caca which carry the
state on the driver handle). The globals survive across driver
teardown/re-init, so the new capacity variable is explicitly reset
to 0 in the *_free path alongside clearing the pointer to NULL;
without that, re-init after teardown could skip the realloc on a
same-or-smaller first frame and memcpy into the freed pointer.
Thread-safety: set_texture_frame and the frame read-site both run on
the video thread (threaded video) or main thread (non-threaded),
sequentially within the same loop iteration. No synchronization
required, none added. The realloc pattern additionally closes a
transient NULL window that existed between the free and malloc in
the original code.1 parent 7a488b8 commit 05de9cb
2 files changed
Lines changed: 40 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
371 | 372 | | |
372 | 373 | | |
373 | 374 | | |
| 375 | + | |
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
| |||
391 | 393 | | |
392 | 394 | | |
393 | 395 | | |
394 | | - | |
| 396 | + | |
| 397 | + | |
395 | 398 | | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
| 399 | + | |
| 400 | + | |
404 | 401 | | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
| 402 | + | |
411 | 403 | | |
412 | | - | |
| 404 | + | |
413 | 405 | | |
414 | | - | |
415 | | - | |
416 | | - | |
417 | | - | |
418 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
419 | 412 | | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
420 | 419 | | |
421 | 420 | | |
422 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
532 | 533 | | |
533 | 534 | | |
534 | 535 | | |
| 536 | + | |
535 | 537 | | |
536 | 538 | | |
537 | 539 | | |
| |||
566 | 568 | | |
567 | 569 | | |
568 | 570 | | |
569 | | - | |
| 571 | + | |
| 572 | + | |
570 | 573 | | |
571 | | - | |
572 | | - | |
573 | | - | |
574 | | - | |
575 | | - | |
576 | | - | |
577 | | - | |
578 | | - | |
| 574 | + | |
| 575 | + | |
579 | 576 | | |
580 | | - | |
581 | | - | |
582 | | - | |
| 577 | + | |
583 | 578 | | |
584 | | - | |
| 579 | + | |
585 | 580 | | |
586 | | - | |
587 | | - | |
588 | | - | |
589 | | - | |
590 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
591 | 587 | | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
592 | 594 | | |
593 | 595 | | |
594 | 596 | | |
| |||
0 commit comments