mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-20 03:25:16 +00:00
static analysis: fix memory leak in decompress
This commit is contained in:
parent
9b4fdd5288
commit
2fb7534cf3
1 changed files with 5 additions and 7 deletions
|
@ -3,6 +3,7 @@
|
|||
// http://www.gnu.org/licenses/gpl-2.0.txt
|
||||
|
||||
#include <string.h>
|
||||
#include <vector>
|
||||
#include "lz.h"
|
||||
|
||||
void decode_range(unsigned int *range, unsigned int *code, unsigned char **src)
|
||||
|
@ -123,19 +124,17 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
|||
{
|
||||
int result;
|
||||
|
||||
unsigned char *tmp = new unsigned char[0xCC8];
|
||||
|
||||
int offset = 0;
|
||||
int bit_flag = 0;
|
||||
int data_length = 0;
|
||||
int data_offset = 0;
|
||||
|
||||
unsigned char *tmp_sect1, *tmp_sect2, *tmp_sect3;
|
||||
unsigned char *buf_start, *buf_end;
|
||||
const unsigned char *buf_start, *buf_end;
|
||||
unsigned char prev = 0;
|
||||
|
||||
unsigned char *start = out;
|
||||
unsigned char *end = (out + size);
|
||||
const unsigned char *end = (out + size);
|
||||
unsigned char head = in[0];
|
||||
|
||||
unsigned int range = 0xFFFFFFFF;
|
||||
|
@ -154,6 +153,8 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
|||
else
|
||||
{
|
||||
// Set up a temporary buffer (sliding window).
|
||||
std::vector<unsigned char> tmp_vec(0xCC8);
|
||||
unsigned char* tmp = tmp_vec.data();
|
||||
memset(tmp, 0x80, 0xCA8);
|
||||
while (true)
|
||||
{
|
||||
|
@ -254,14 +255,12 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
|||
// Underflow.
|
||||
if (buf_start < out)
|
||||
{
|
||||
delete[] tmp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Overflow.
|
||||
if (buf_end > end)
|
||||
{
|
||||
delete[] tmp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -279,6 +278,5 @@ int decompress(unsigned char *out, unsigned char *in, unsigned int size)
|
|||
}
|
||||
result = static_cast<int>(start - out);
|
||||
}
|
||||
delete[] tmp;
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue