In ImageMagick before 7.0.8-25 and GraphicsMagick through 1.3.31, several memory leaks exist in WritePDFImage in coders/pdf.c.
### 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 ---
