mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
94 stars 70 forks source link

aper: Fix regression reusing allocated sptr decoding CHOICE #104

Closed pespin closed 2 years ago

pespin commented 2 years ago

Recent commit abd1faa6cf396ab1a4cddbe637f80316aa2cdef0 broke passing already existing output decoded structre as sptr. As a result, a new sptr was always allocated, and the old one leaked.

Fixes: abd1faa6cf396ab1a4cddbe637f80316aa2cdef0

pespin commented 2 years ago

@mouse07410 please merge this ASAP.

mouse07410 commented 2 years ago

Wow... @pespin good catch!! Thank you!

pespin commented 2 years ago

@mouse07410 it was breaking my osmo-cbc unit tests ;)

It may be good to add a unit test under asn1c which does:

void *buf = malloc(1000);
void *old_buf = buf;
aper_decode_complete(NULL, &asn_DEF_whatever_type_to_test_like_CHOICE,
            (void **)&pdu, input_encoded_arr, sizeof(input_encoded_arr));
assert (old_buf == buf);

Without this patch applied, the unit test would fail, since buf would be a newly allocated buffer.

mouse07410 commented 2 years ago

@pespin I agree. Would you be able to add such a test?