Skip to content

Commit b48c97f

Browse files
committed
Free, close, and unlink files when failure happens
1 parent 7f99d0c commit b48c97f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

backend/ipp.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,12 +1400,18 @@ 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+
if (tmpfilename[0])
1404+
unlink(tmpfilename);
14031405
return (CUPS_BACKEND_FAILED);
14041406
}
14051407

14061408
if ((bytes = backendRunLoop(-1, fd, snmp_fd, &(addrlist->addr), 0, 0,
14071409
backendNetworkSideCB)) < 0)
1410+
{
1411+
if (tmpfilename[0])
1412+
unlink(tmpfilename);
14081413
return (CUPS_BACKEND_FAILED);
1414+
}
14091415

14101416
compatsize += bytes;
14111417

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)