In ImageMagick before 7.0.8-25 and GraphicsMagick through 1.3.31, several memory leaks exist in WritePDFImage in coders/pdf.c.
cpe:2.3:a:imagemagick:imagemagick:*:*:*:*:*:*:*:*
E982CE9C-89F7-4A5D-B036-A9A483493D5B
6.9.10-25
cpe:2.3:a:imagemagick:imagemagick:*:*:*:*:*:*:*:*
2F7DF2A1-ADDE-48C4-BD39-CCA15D0D767A
7.0.8-25
7.0.0-0
OR
cpe:2.3:a:graphicsmagick:graphicsmagick:*:*:*:*:*:*:*:*
DA564A9F-4001-4846-A8BB-EAD95674C890
1.3.31
OR
cpe:2.3:o:opensuse:leap:15.0:*:*:*:*:*:*:*
F1E78106-58E6-4D59-990F-75DA575BFAD9
OR
cpe:2.3:o:debian:debian_linux:10.0:*:*:*:*:*:*:*
07B237A9-69A3-4A9C-9DA0-4E06BD37AE73
OR
cpe:2.3:o:canonical:ubuntu_linux:16.04:*:*:*:lts:*:*:*
F7016A2A-8365-4F1A-89A2-7A19F2BCAE5B
cpe:2.3:o:canonical:ubuntu_linux:18.04:*:*:*:lts:*:*:*
23A7C53F-B80F-4E6A-AFA9-58EEA84BE11D
cpe:2.3:o:canonical:ubuntu_linux:18.10:*:*:*:*:*:*:*
07C312A0-CD2C-4B9C-B064-6409B25C278F
cpe:2.3:o:canonical:ubuntu_linux:19.04:*:*:*:*:*:*:*
CD783B0C-9246-47D9-A937-6144FE8BFF0F
OR
### Prerequisites

- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported

### Description
<!-- A description of the bug or feature -->
Potential memory leak in function WritePDFImage in coders/pdf.c, which is similar to but different from #576. 
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
     Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
**xref** is allocated at line [L1362](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1362) or reallocated at line [L1499](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1499).
```c 
1362: xref=(MagickOffsetType *) AcquireQuantumMemory(2048UL,sizeof(*xref));

1499:  xref=(MagickOffsetType *) ResizeQuantumMemory(xref,(size_t) count+2048UL,
        sizeof(*xref));
```
However, when the function returns with *MagickFalse* (such as [L1902](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1902) and [L1912](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1912)), **xref** was neither passed outside to the caller function nor freed. I believe the two positions needs to free **xref** because **xref** is freed at the **default case** at [L1931](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1931) while the 2 positions locates in another 2 cases of a switch statement. So memory leak can happen at line **1902** and **1912**.

There are many similar positions including [L1965](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1965), [L2011](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2011), [L2021](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2021), [L2082](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2082), [L2179](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2179), [L2427](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1362), [L2437](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2437), [L2488](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2488), [L2529](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2529), [L2539](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2539), [L2594](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2594), [L2682](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2682) and [L2894](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2894).

### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->

- ImageMagick version: ImageMagick-4f0ea40e2a090e245f31d1f05247520d6e7eb4ca
- Environment (Operating system, version and so on):  Ubuntu 16.04 + VS Code
- Additional information: code review

<!-- Thanks for reporting the issue to ImageMagick! -->
Credit to Bingchang Liu of VARAS of IIE
Potential Memory Leak in WritePDFImage in coders/pdf.c different from #576
This is a GitHub Issue
repo:ImageMagick
owner:ImageMagick
Title : Potential Memory Leak in WritePDFImage in coders/pdf.c different from #576
Issue date:

--- start body ---
### Prerequisites

- [x] I have written a descriptive issue title
- [x] I have verified that I am using the latest version of ImageMagick
- [x] I have searched [open](https://github.com/ImageMagick/ImageMagick/issues) and [closed](https://github.com/ImageMagick/ImageMagick/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported

### Description
<!-- A description of the bug or feature -->
Potential memory leak in function WritePDFImage in coders/pdf.c, which is similar to but different from #576. 
### Steps to Reproduce
<!-- List of steps, sample code, failing test or link to a project that reproduces the behavior.
     Make sure you place a stack trace inside a code (```) block to avoid linking unrelated issues -->
**xref** is allocated at line [L1362](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1362) or reallocated at line [L1499](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1499).
```c 
1362: xref=(MagickOffsetType *) AcquireQuantumMemory(2048UL,sizeof(*xref));

1499:  xref=(MagickOffsetType *) ResizeQuantumMemory(xref,(size_t) count+2048UL,
        sizeof(*xref));
```
However, when the function returns with *MagickFalse* (such as [L1902](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1902) and [L1912](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1912)), **xref** was neither passed outside to the caller function nor freed. I believe the two positions needs to free **xref** because **xref** is freed at the **default case** at [L1931](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1931) while the 2 positions locates in another 2 cases of a switch statement. So memory leak can happen at line **1902** and **1912**.

There are many similar positions including [L1965](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1965), [L2011](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2011), [L2021](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2021), [L2082](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2082), [L2179](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2179), [L2427](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L1362), [L2437](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2437), [L2488](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2488), [L2529](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2529), [L2539](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2539), [L2594](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2594), [L2682](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2682) and [L2894](https://github.com/ImageMagick/ImageMagick/blob/master/coders/pdf.c#L2894).

### System Configuration
<!-- Tell us about the environment where you are experiencing the bug -->

- ImageMagick version: ImageMagick-4f0ea40e2a090e245f31d1f05247520d6e7eb4ca
- Environment (Operating system, version and so on):  Ubuntu 16.04 + VS Code
- Additional information: code review

<!-- Thanks for reporting the issue to ImageMagick! -->
Credit to Bingchang Liu of VARAS of IIE
--- end body ---

comments :
--- start comments ---

--- end comments ---