epson: don't leak memory if realloc() fails

merge-requests/1/head
Nils Philippsen 2013-11-07 14:29:28 +01:00
rodzic dc76e7cce4
commit d835d9d565
1 zmienionych plików z 3 dodań i 1 usunięć

Wyświetl plik

@ -1854,7 +1854,7 @@ static EpsonHdrUnion
command (Epson_Scanner * s, u_char * cmd, size_t cmd_size, command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
SANE_Status * status) SANE_Status * status)
{ {
EpsonHdrUnion hdrunion; EpsonHdrUnion hdrunion, hdrunion_bak;
EpsonHdr head; EpsonHdr head;
u_char *buf; u_char *buf;
int count; int count;
@ -1937,9 +1937,11 @@ command (Epson_Scanner * s, u_char * cmd, size_t cmd_size,
count = head->count2 * 255 + head->count1; count = head->count2 * 255 + head->count1;
DBG (4, "count %d\n", count); DBG (4, "count %d\n", count);
hdrunion_bak = hdrunion;
if (NULL == (hdrunion = realloc (hdrunion, if (NULL == (hdrunion = realloc (hdrunion,
sizeof (EpsonHdrUnionRec) + count))) sizeof (EpsonHdrUnionRec) + count)))
{ {
free(hdrunion_bak);
DBG (1, "out of memory (line %d)\n", __LINE__); DBG (1, "out of memory (line %d)\n", __LINE__);
*status = SANE_STATUS_NO_MEM; *status = SANE_STATUS_NO_MEM;
return (EpsonHdrUnion) 0; return (EpsonHdrUnion) 0;