Hi, developers of libredwg:
Recently, I test some binaries instrumented with ASAN in libredwg . Unfortunately, some incurred crashes with the following error information. Any help would be greatly appreciated from you :D

For binary **dwgread**:
crash input:
https://github.com/Yhcrown/fuzzing-crashes/blob/main/validated/dwgread/0
output:
```
=================================================================
==78039==ERROR: AddressSanitizer: attempting double-free on 0x6040000180d0 in thread T0:
    #0 0x56381d83f022 in free (/workspace/libredwg/programs/dwgread+0x22c022) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)
    #1 0x56381dc0bb42 in dwg_free_XRECORD_private /workspace/libredwg/src/./dwg.spec:6792:3
    #2 0x56381db59ad2 in dwg_free_XRECORD /workspace/libredwg/src/./dwg.spec:6739:1
    #3 0x56381dc0e7ae in dwg_free_object /workspace/libredwg/src/free.c:1060:7
    #4 0x56381dc110d6 in dwg_free /workspace/libredwg/src/free.c:1512:13
    #5 0x56381d87b4ca in main /workspace/libredwg/programs/dwgread.c:333:7
    #6 0x7f1ea9659d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #7 0x7f1ea9659e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x56381d7bc484 in _start (/workspace/libredwg/programs/dwgread+0x1a9484) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)

0x6040000180d0 is located 0 bytes inside of 48-byte region [0x6040000180d0,0x604000018100)
freed by thread T0 here:
    #0 0x56381d83f022 in free (/workspace/libredwg/programs/dwgread+0x22c022) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)
    #1 0x56381d9dec2c in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6781:17

previously allocated by thread T0 here:
    #0 0x56381d83f2ce in __interceptor_malloc (/workspace/libredwg/programs/dwgread+0x22c2ce) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)
    #1 0x56381d9de8c6 in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6776:27

SUMMARY: AddressSanitizer: double-free (/workspace/libredwg/programs/dwgread+0x22c022) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7) in free
==78039==ABORTING

```


For binary **dwgbmp**:
crash input:
https://github.com/Yhcrown/fuzzing-crashes/blob/main/validated/dwgbmp/0
output:
```
=================================================================
==82075==ERROR: AddressSanitizer: attempting double-free on 0x6040000051d0 in thread T0:
    #0 0x5584dfc9c002 in free (/workspace/libredwg/programs/dwgbmp+0x19d002) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)
    #1 0x5584e0069372 in dwg_free_XRECORD_private /workspace/libredwg/src/./dwg.spec:6792:3
    #2 0x5584dffb7302 in dwg_free_XRECORD /workspace/libredwg/src/./dwg.spec:6739:1
    #3 0x5584e006bfde in dwg_free_object /workspace/libredwg/src/free.c:1060:7
    #4 0x5584e006e906 in dwg_free /workspace/libredwg/src/free.c:1512:13
    #5 0x5584dfcd8121 in get_bmp /workspace/libredwg/programs/dwgbmp.c
    #6 0x5584dfcd8121 in main /workspace/libredwg/programs/dwgbmp.c:301:11
    #7 0x7f6d1a2b0d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x7f6d1a2b0e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #9 0x5584dfc19464 in _start (/workspace/libredwg/programs/dwgbmp+0x11a464) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)

0x6040000051d0 is located 0 bytes inside of 48-byte region [0x6040000051d0,0x604000005200)
freed by thread T0 here:
    #0 0x5584dfc9c002 in free (/workspace/libredwg/programs/dwgbmp+0x19d002) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)
    #1 0x5584dfe3c45c in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6781:17

previously allocated by thread T0 here:
    #0 0x5584dfc9c2ae in __interceptor_malloc (/workspace/libredwg/programs/dwgbmp+0x19d2ae) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)
    #1 0x5584dfe3c0f6 in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6776:27

SUMMARY: AddressSanitizer: double-free (/workspace/libredwg/programs/dwgbmp+0x19d002) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8) in free
==82075==ABORTING
```

For binary **dwglayers**:
crash input:
https://github.com/Yhcrown/fuzzing-crashes/blob/main/validated/dwglayers/9
output：
```
0
Tavolo 2
Tavolo 3
Defpoints
ADSK_SYSTEM_LIGHTS
=================================================================
==53887==ERROR: AddressSanitizer: attempting double-free on 0x6040000b8850 in thread T0:
    #0 0x5639cf98aff2 in free (/workspace/libredwg/programs/dwglayers+0x19cff2) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)
    #1 0x5639cfd57062 in dwg_free_XRECORD_private /workspace/libredwg/src/./dwg.spec:6792:3
    #2 0x5639cfca4ff2 in dwg_free_XRECORD /workspace/libredwg/src/./dwg.spec:6739:1
    #3 0x5639cfd59cce in dwg_free_object /workspace/libredwg/src/free.c:1060:7
    #4 0x5639cfd5c5f6 in dwg_free /workspace/libredwg/src/free.c:1512:13
    #5 0x5639cf9c6bf1 in main /workspace/libredwg/programs/dwglayers.c:214:5
    #6 0x7f96269ffd8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #7 0x7f96269ffe3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x5639cf908454 in _start (/workspace/libredwg/programs/dwglayers+0x11a454) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)

0x6040000b8850 is located 0 bytes inside of 48-byte region [0x6040000b8850,0x6040000b8880)
freed by thread T0 here:
    #0 0x5639cf98aff2 in free (/workspace/libredwg/programs/dwglayers+0x19cff2) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)
    #1 0x5639cfb2a14c in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6781:17

previously allocated by thread T0 here:
    #0 0x5639cf98b29e in __interceptor_malloc (/workspace/libredwg/programs/dwglayers+0x19d29e) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)
    #1 0x5639cfb29de6 in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6776:27

SUMMARY: AddressSanitizer: double-free (/workspace/libredwg/programs/dwglayers+0x19cff2) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781) in free
==53887==ABORTING
```


### Verification steps：

```
git clone https://github.com/LibreDWG/libredwg
cd libredwg/
sh ./autogen.sh
CC=clang CFLAGS='-U_FORTIFY_SOURCE -fsanitize=address' LDFLAGS='-U_FORTIFY_SOURCE -fsanitize=address' ./configure --disable-shared  --disable-write --enable-trace --enable-release
make -j 
./binary ./crash-input
```
enviroment:
Ubuntu 22.04 LTS
Linux lab-pro 4.15.0-147-generic
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Ubuntu clang version 14.0.6

**Thanks & Best regards !**
attempting double-free in function dwg_free_XRECORD_private
This is a GitHub Issue
repo:libredwg
owner:LibreDWG
Title : attempting double-free in function dwg_free_XRECORD_private
Issue date:

--- start body ---
Hi, developers of libredwg:
Recently, I test some binaries instrumented with ASAN in libredwg . Unfortunately, some incurred crashes with the following error information. Any help would be greatly appreciated from you :D

For binary **dwgread**:
crash input:
https://github.com/Yhcrown/fuzzing-crashes/blob/main/validated/dwgread/0
output:
```
=================================================================
==78039==ERROR: AddressSanitizer: attempting double-free on 0x6040000180d0 in thread T0:
    #0 0x56381d83f022 in free (/workspace/libredwg/programs/dwgread+0x22c022) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)
    #1 0x56381dc0bb42 in dwg_free_XRECORD_private /workspace/libredwg/src/./dwg.spec:6792:3
    #2 0x56381db59ad2 in dwg_free_XRECORD /workspace/libredwg/src/./dwg.spec:6739:1
    #3 0x56381dc0e7ae in dwg_free_object /workspace/libredwg/src/free.c:1060:7
    #4 0x56381dc110d6 in dwg_free /workspace/libredwg/src/free.c:1512:13
    #5 0x56381d87b4ca in main /workspace/libredwg/programs/dwgread.c:333:7
    #6 0x7f1ea9659d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #7 0x7f1ea9659e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x56381d7bc484 in _start (/workspace/libredwg/programs/dwgread+0x1a9484) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)

0x6040000180d0 is located 0 bytes inside of 48-byte region [0x6040000180d0,0x604000018100)
freed by thread T0 here:
    #0 0x56381d83f022 in free (/workspace/libredwg/programs/dwgread+0x22c022) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)
    #1 0x56381d9dec2c in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6781:17

previously allocated by thread T0 here:
    #0 0x56381d83f2ce in __interceptor_malloc (/workspace/libredwg/programs/dwgread+0x22c2ce) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7)
    #1 0x56381d9de8c6 in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6776:27

SUMMARY: AddressSanitizer: double-free (/workspace/libredwg/programs/dwgread+0x22c022) (BuildId: d78e358e2f9168522e4967bcbcf9dbaf26625dc7) in free
==78039==ABORTING

```


For binary **dwgbmp**:
crash input:
https://github.com/Yhcrown/fuzzing-crashes/blob/main/validated/dwgbmp/0
output:
```
=================================================================
==82075==ERROR: AddressSanitizer: attempting double-free on 0x6040000051d0 in thread T0:
    #0 0x5584dfc9c002 in free (/workspace/libredwg/programs/dwgbmp+0x19d002) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)
    #1 0x5584e0069372 in dwg_free_XRECORD_private /workspace/libredwg/src/./dwg.spec:6792:3
    #2 0x5584dffb7302 in dwg_free_XRECORD /workspace/libredwg/src/./dwg.spec:6739:1
    #3 0x5584e006bfde in dwg_free_object /workspace/libredwg/src/free.c:1060:7
    #4 0x5584e006e906 in dwg_free /workspace/libredwg/src/free.c:1512:13
    #5 0x5584dfcd8121 in get_bmp /workspace/libredwg/programs/dwgbmp.c
    #6 0x5584dfcd8121 in main /workspace/libredwg/programs/dwgbmp.c:301:11
    #7 0x7f6d1a2b0d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x7f6d1a2b0e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #9 0x5584dfc19464 in _start (/workspace/libredwg/programs/dwgbmp+0x11a464) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)

0x6040000051d0 is located 0 bytes inside of 48-byte region [0x6040000051d0,0x604000005200)
freed by thread T0 here:
    #0 0x5584dfc9c002 in free (/workspace/libredwg/programs/dwgbmp+0x19d002) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)
    #1 0x5584dfe3c45c in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6781:17

previously allocated by thread T0 here:
    #0 0x5584dfc9c2ae in __interceptor_malloc (/workspace/libredwg/programs/dwgbmp+0x19d2ae) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8)
    #1 0x5584dfe3c0f6 in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6776:27

SUMMARY: AddressSanitizer: double-free (/workspace/libredwg/programs/dwgbmp+0x19d002) (BuildId: ec27550ef88545eef0fdc77a46b25d158c3c8aa8) in free
==82075==ABORTING
```

For binary **dwglayers**:
crash input:
https://github.com/Yhcrown/fuzzing-crashes/blob/main/validated/dwglayers/9
output：
```
0
Tavolo 2
Tavolo 3
Defpoints
ADSK_SYSTEM_LIGHTS
=================================================================
==53887==ERROR: AddressSanitizer: attempting double-free on 0x6040000b8850 in thread T0:
    #0 0x5639cf98aff2 in free (/workspace/libredwg/programs/dwglayers+0x19cff2) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)
    #1 0x5639cfd57062 in dwg_free_XRECORD_private /workspace/libredwg/src/./dwg.spec:6792:3
    #2 0x5639cfca4ff2 in dwg_free_XRECORD /workspace/libredwg/src/./dwg.spec:6739:1
    #3 0x5639cfd59cce in dwg_free_object /workspace/libredwg/src/free.c:1060:7
    #4 0x5639cfd5c5f6 in dwg_free /workspace/libredwg/src/free.c:1512:13
    #5 0x5639cf9c6bf1 in main /workspace/libredwg/programs/dwglayers.c:214:5
    #6 0x7f96269ffd8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #7 0x7f96269ffe3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
    #8 0x5639cf908454 in _start (/workspace/libredwg/programs/dwglayers+0x11a454) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)

0x6040000b8850 is located 0 bytes inside of 48-byte region [0x6040000b8850,0x6040000b8880)
freed by thread T0 here:
    #0 0x5639cf98aff2 in free (/workspace/libredwg/programs/dwglayers+0x19cff2) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)
    #1 0x5639cfb2a14c in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6781:17

previously allocated by thread T0 here:
    #0 0x5639cf98b29e in __interceptor_malloc (/workspace/libredwg/programs/dwglayers+0x19d29e) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781)
    #1 0x5639cfb29de6 in dwg_decode_XRECORD_private /workspace/libredwg/src/./dwg.spec:6776:27

SUMMARY: AddressSanitizer: double-free (/workspace/libredwg/programs/dwglayers+0x19cff2) (BuildId: be6310fd94058a60a255f09e79d9fc62db79b781) in free
==53887==ABORTING
```


### Verification steps：

```
git clone https://github.com/LibreDWG/libredwg
cd libredwg/
sh ./autogen.sh
CC=clang CFLAGS='-U_FORTIFY_SOURCE -fsanitize=address' LDFLAGS='-U_FORTIFY_SOURCE -fsanitize=address' ./configure --disable-shared  --disable-write --enable-trace --enable-release
make -j 
./binary ./crash-input
```
enviroment:
Ubuntu 22.04 LTS
Linux lab-pro 4.15.0-147-generic
gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0
Ubuntu clang version 14.0.6

**Thanks & Best regards !**
--- end body ---
