Files
b1b1f94c42 [NFC] Fix memory leaks & double-frees in supported-card parsers, app lifecycle & DESFire (#1030)
* nfc: fix double-free of card_number_str in Plantain parser

printf_plantain_data() freed purse->card_number_str, then the caller freed the same (non-NULL) pointer again at the end of the parse -> double-free / heap corruption on every Plantain card. Remove the free inside the print helper; the caller that allocated it owns the free.

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: fix double-free + secondary-ticket leak in SZPPK parser

In the second-ticket branch the cleanup freed primary_ticket.* (already freed just above) instead of the freshly-allocated secondary_ticket.*, causing a double-free of the primary strings and a leak of all four secondary strings on two-trip tickets. Free the secondary_ticket.* members.

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: fix double-free + secondary-ticket leak in SEVPPK parser

Same copy-paste bug as SZPPK: the second-ticket branch freed primary_ticket.* (already freed) instead of secondary_ticket.*, double-freeing the primary strings and leaking the secondary ones on two-trip tickets. Free the secondary_ticket.* members.

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: fix double-free + secondary-ticket leak in SK parser

Same copy-paste bug as SZPPK/SEVPPK: the second-ticket branch freed primary_ticket.* (already freed) instead of secondary_ticket.*, double-freeing the primary strings and leaking the secondary ones on two-trip tickets. Free the secondary_ticket.* members.

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: fix restricted_weekday_string leak in Saflok parser

restricted_weekday_string was allocated and only read via furi_string_get_cstr; the file had no furi_string_free at all, leaking one FuriString on every Saflok card parse (both MFC and UL-C variants). Free it before the do/while(false) exits (after #endif so it applies to both SL_PROTO builds).

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: free api_resolver in nfc_app_free (fix per-launch leak)

instance->api_resolver (composite_api_resolver_alloc + two composite_api_resolver_add nodes) was never freed; nfc_supported_cards only borrows it. Leaked the resolver struct plus its two list nodes on every NFC-app open->close. Free it after nfc_supported_cards_free (its only user).

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: fix Stream + storage-record leak on CUID dict open failure

When a CUID dictionary passed keys_dict_check_presence but buffered_file_stream_open then failed, cleanup did only buffered_file_stream_close + free(dict), leaking the Stream object and the RECORD_STORAGE reference opened just above. Use keys_dict_free(dict), which closes+frees the stream, frees the dict, and closes RECORD_STORAGE, matching the total_keys==0 path.

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* nfc: fix ~15x RAM over-allocation of DESFire file_data array

mf_desfire_file_data_array_config.type_size used sizeof(MfDesfireData) (~60+ bytes) but the element type is MfDesfireFileData ({ SimpleArray* data; } = 4 bytes), so every file slot over-allocated ~15x, scaled by (files x applications) on the card. Use sizeof(MfDesfireFileData). Consistent stride, so no behavior change beyond reduced heap use.

Part of #1029

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* changelog: NFC memory leaks & double-frees (PR #1030, Fixes #1029)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-05 18:16:46 +03:00
..
2025-06-30 19:53:45 +03:00
2025-06-30 19:53:45 +03:00
2025-06-30 19:53:45 +03:00
2025-06-30 19:53:45 +03:00
2025-06-30 19:53:45 +03:00
2025-06-30 19:53:45 +03:00