Skip to content

Commit

Permalink
Fix memory leaks found by Coverity (Issue #5375)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Aug 21, 2018
1 parent 5c463d3 commit 3416fe9
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 28 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CHANGES - 2.3b6 - 2018-08-19
CHANGES - 2.3b6 - 2018-08-21
============================

Changes in CUPS v2.3b6
Expand All @@ -21,6 +21,7 @@ Changes in CUPS v2.3b6
- Fixed some typos in the label printer drivers (Issue #5350)
- The IPP Everywhere "driver" no longer does local filtering when printing to
a shared CUPS printer (Issue #5361)
- Fixed some memory leaks discovered by Coverity (Issue #5375)
- The scheduler was being backgrounded on macOS, causing applications to spin
(rdar://40436080)
- The scheduler did not validate that required initial request attributes were
Expand Down
2 changes: 2 additions & 0 deletions backend/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,8 @@ update_reasons(ipp_attribute_t *attr, /* I - printer-state-reasons or NULL */
}
}

cupsArrayDelete(new_reasons);

_cupsMutexUnlock(&report_mutex);

/*
Expand Down
6 changes: 4 additions & 2 deletions cgi-bin/search.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* Search routines for CUPS.
*
* Copyright 2007-2014 by Apple Inc.
* Copyright 2007-2018 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more information.
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
*/

/*
Expand Down Expand Up @@ -361,4 +362,5 @@ void
cgiFreeSearch(void *search) /* I - Search context */
{
regfree((regex_t *)search);
free(search);
}
6 changes: 4 additions & 2 deletions cups/http-addrlist.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* HTTP address list routines for CUPS.
*
* Copyright 2007-2017 by Apple Inc.
* Copyright 2007-2018 by Apple Inc.
* Copyright 1997-2007 by Easy Software Products, all rights reserved.
*
* Licensed under Apache License v2.0. See the file "LICENSE" for more information.
* Licensed under Apache License v2.0. See the file "LICENSE" for more
* information.
*/

/*
Expand Down Expand Up @@ -612,6 +613,7 @@ httpAddrGetList(const char *hostname, /* I - Hostname, IP address, or NULL for p
if (!temp)
{
httpAddrFreeList(first);
freeaddrinfo(results);
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
return (NULL);
}
Expand Down
2 changes: 1 addition & 1 deletion cups/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -3915,7 +3915,7 @@ http_create(
if ((http = calloc(sizeof(http_t), 1)) == NULL)
{
_cupsSetError(IPP_STATUS_ERROR_INTERNAL, strerror(errno), 0);
httpAddrFreeList(addrlist);
httpAddrFreeList(myaddrlist);
return (NULL);
}

Expand Down
6 changes: 4 additions & 2 deletions ppdc/ppdc-source.cxx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//
// Source class for the CUPS PPD Compiler.
//
// Copyright 2007-2014 by Apple Inc.
// Copyright 2007-2018 by Apple Inc.
// Copyright 2002-2007 by Easy Software Products.
//
// Licensed under Apache License v2.0. See the file "LICENSE" for more information.
// Licensed under Apache License v2.0. See the file "LICENSE" for more
// information.
//

//
Expand Down Expand Up @@ -2665,6 +2666,7 @@ ppdcSource::scan_file(ppdcFile *fp, // I - File to read
// Add it to the current option...
if (!o)
{
c->release();
_cupsLangPrintf(stderr,
_("ppdc: Choice found on line %d of %s with no "
"Option."), fp->line, fp->filename);
Expand Down
40 changes: 20 additions & 20 deletions scheduler/cups-driverd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static ppd_info_t *add_ppd(const char *filename, const char *name,
size_t size, int model_number, int type,
const char *scheme);
static int cat_drv(const char *name, int request_id);
static int cat_ppd(const char *name, int request_id);
static void cat_ppd(const char *name, int request_id);
static int cat_static(const char *name, int request_id);
static int cat_tar(const char *name, int request_id);
static int compare_inodes(struct stat *a, struct stat *b);
Expand All @@ -163,12 +163,12 @@ static int compare_names(const ppd_info_t *p0,
const ppd_info_t *p1);
static int compare_ppds(const ppd_info_t *p0,
const ppd_info_t *p1);
static int dump_ppds_dat(const char *filename);
static void dump_ppds_dat(const char *filename);
static void free_array(cups_array_t *a);
static cups_file_t *get_file(const char *name, int request_id,
const char *subdir, char *buffer,
size_t bufsize, char **subfile);
static int list_ppds(int request_id, int limit, const char *opt);
static void list_ppds(int request_id, int limit, const char *opt);
static int load_drivers(cups_array_t *include,
cups_array_t *exclude);
static int load_drv(const char *filename, const char *name,
Expand Down Expand Up @@ -204,13 +204,13 @@ main(int argc, /* I - Number of command-line args */
*/

if (argc == 3 && !strcmp(argv[1], "cat"))
return (cat_ppd(argv[2], 0));
cat_ppd(argv[2], 0);
else if ((argc == 2 || argc == 3) && !strcmp(argv[1], "dump"))
return (dump_ppds_dat(argv[2]));
dump_ppds_dat(argv[2]);
else if (argc == 4 && !strcmp(argv[1], "get"))
return (cat_ppd(argv[3], atoi(argv[2])));
cat_ppd(argv[3], atoi(argv[2]));
else if (argc == 5 && !strcmp(argv[1], "list"))
return (list_ppds(atoi(argv[2]), atoi(argv[3]), argv[4]));
list_ppds(atoi(argv[2]), atoi(argv[3]), argv[4]);
else
{
fputs("Usage: cups-driverd cat ppd-name\n", stderr);
Expand Down Expand Up @@ -428,7 +428,7 @@ cat_drv(const char *name, /* I - PPD name */
* 'cat_ppd()' - Copy a PPD file to stdout.
*/

static int /* O - Exit code */
static void
cat_ppd(const char *name, /* I - PPD name */
int request_id) /* I - Request ID for response? */
{
Expand All @@ -445,7 +445,7 @@ cat_ppd(const char *name, /* I - PPD name */
if (strstr(name, "../"))
{
fputs("ERROR: Invalid PPD name.\n", stderr);
return (1);
exit(1);
}

strlcpy(scheme, name, sizeof(scheme));
Expand Down Expand Up @@ -475,11 +475,11 @@ cat_ppd(const char *name, /* I - PPD name */
puts("Content-Type: application/ipp\n");

if (!scheme[0])
return (cat_static(name, request_id));
exit(cat_static(name, request_id));
else if (!strcmp(scheme, "drv"))
return (cat_drv(name, request_id));
exit(cat_drv(name, request_id));
else if (!strcmp(scheme, "file"))
return (cat_tar(name, request_id));
exit(cat_tar(name, request_id));
else
{
/*
Expand Down Expand Up @@ -517,7 +517,7 @@ cat_ppd(const char *name, /* I - PPD name */
cupsdSendIPPTrailer();
}

return (1);
exit(1);
}

/*
Expand Down Expand Up @@ -547,15 +547,15 @@ cat_ppd(const char *name, /* I - PPD name */

fprintf(stderr, "ERROR: [cups-driverd] Unable to execute \"%s\" - %s\n",
line, strerror(errno));
return (1);
exit(1);
}
}

/*
* Return with no errors...
* Exit with no errors...
*/

return (0);
exit(0);
}


Expand Down Expand Up @@ -778,7 +778,7 @@ compare_ppds(const ppd_info_t *p0, /* I - First PPD file */
* 'dump_ppds_dat()' - Dump the contents of the ppds.dat file.
*/

static int /* O - Exit status */
static void
dump_ppds_dat(const char *filename) /* I - Filename */
{
char temp[1024]; /* ppds.dat filename */
Expand Down Expand Up @@ -810,7 +810,7 @@ dump_ppds_dat(const char *filename) /* I - Filename */
ppd->record.make_and_model, ppd->record.device_id,
ppd->record.scheme);

return (0);
exit(0);
}


Expand Down Expand Up @@ -1004,7 +1004,7 @@ get_file(const char *name, /* I - Name */
* 'list_ppds()' - List PPD files.
*/

static int /* O - Exit code */
static void
list_ppds(int request_id, /* I - Request ID */
int limit, /* I - Limit */
const char *opt) /* I - Option argument */
Expand Down Expand Up @@ -1566,7 +1566,7 @@ list_ppds(int request_id, /* I - Request ID */
if (request_id)
cupsdSendIPPTrailer();

return (0);
exit(0);
}


Expand Down

0 comments on commit 3416fe9

Please sign in to comment.