Skip to content

Commit c986de2

Browse files
committed
Free, close, and unlink files when failure happens
1 parent 0f1fd69 commit c986de2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

backend/ipp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,12 +1400,20 @@ main(int argc, /* I - Number of command-line args */
14001400
if ((compatsize = write(fd, buffer, (size_t)bytes)) < 0)
14011401
{
14021402
perror("DEBUG: Unable to write temporary file");
1403+
close(fd);
1404+
if (tmpfilename[0])
1405+
unlink(tmpfilename);
14031406
return (CUPS_BACKEND_FAILED);
14041407
}
14051408

14061409
if ((bytes = backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0,
14071410
backendNetworkSideCB)) < 0)
1411+
{
1412+
close(fd);
1413+
if (tmpfilename[0])
1414+
unlink(tmpfilename);
14081415
return (CUPS_BACKEND_FAILED);
1416+
}
14091417

14101418
compatsize += bytes;
14111419

backend/socket.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
313313

314314
sleep(5);
315315

316+
httpAddrFreeList(addrlist);
317+
if (snmp_fd >= 0)
318+
_cupsSNMPClose(snmp_fd);
319+
if (print_fd != 0)
320+
close(print_fd);
321+
316322
return (CUPS_BACKEND_FAILED);
317323
}
318324

@@ -324,6 +330,11 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */
324330
{
325331
_cupsLangPrintFilter(stderr, "ERROR",
326332
_("The printer is not responding."));
333+
httpAddrFreeList(addrlist);
334+
if (snmp_fd >= 0)
335+
_cupsSNMPClose(snmp_fd);
336+
if (print_fd != 0)
337+
close(print_fd);
327338
return (CUPS_BACKEND_FAILED);
328339
}
329340

0 commit comments

Comments
 (0)