Skip to content

Commit

Permalink
scheduler: Fix memory leaks during create_local_bg_thread()
Browse files Browse the repository at this point in the history
  • Loading branch information
zdohnal committed Sep 20, 2022
1 parent 1904705 commit 4f154cb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
26 changes: 15 additions & 11 deletions cups/ppd-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3269,20 +3269,20 @@ _ppdCreateFromIPP2(
{
keyword = ippGetString(lang_supp, i, NULL);

request = ippNew();
ippSetOperation(request, IPP_OP_GET_PRINTER_ATTRIBUTES);
ippSetRequestId(request, i + 1);
ippAddString(request, IPP_TAG_OPERATION, IPP_CONST_TAG(IPP_TAG_CHARSET), "attributes-charset", NULL, "utf-8");
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, keyword);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer_uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "requested-attributes", NULL, "printer-strings-uri");
request = ippNew();
ippSetOperation(request, IPP_OP_GET_PRINTER_ATTRIBUTES);
ippSetRequestId(request, i + 1);
ippAddString(request, IPP_TAG_OPERATION, IPP_CONST_TAG(IPP_TAG_CHARSET), "attributes-charset", NULL, "utf-8");
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, keyword);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, printer_uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_CONST_TAG(IPP_TAG_KEYWORD), "requested-attributes", NULL, "printer-strings-uri");

response = cupsDoRequest(http, request, resource);
response = cupsDoRequest(http, request, resource);

if ((attr = ippFindAttribute(response, "printer-strings-uri", IPP_TAG_URI)) != NULL)
{
if ((attr = ippFindAttribute(response, "printer-strings-uri", IPP_TAG_URI)) != NULL)
cupsFilePrintf(fp, "*cupsStringsURI %s: \"%s\"\n", keyword, ippGetString(attr, 0, NULL));
}

ippDelete(response);
}
}
}
Expand Down Expand Up @@ -4994,6 +4994,8 @@ _ppdCreateFromIPP2(

cupsFileClose(fp);

_cupsMessageFree(strings);

return (buffer);

/*
Expand All @@ -5006,6 +5008,8 @@ _ppdCreateFromIPP2(
unlink(buffer);
*buffer = '\0';

_cupsMessageFree(strings);

_cupsSetError(IPP_STATUS_ERROR_INTERNAL, _("Printer does not support required IPP attributes or document formats."), 1);

return (NULL);
Expand Down
4 changes: 4 additions & 0 deletions scheduler/ipp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5401,13 +5401,15 @@ create_local_bg_thread(
if ((from = cupsFileOpen(fromppd, "r")) == NULL)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Unable to read generated PPD: %s", printer->name, strerror(errno));
ippDelete(response);
return (NULL);
}

snprintf(toppd, sizeof(toppd), "%s/ppd/%s.ppd", ServerRoot, printer->name);
if ((to = cupsdCreateConfFile(toppd, ConfigFilePerm)) == NULL)
{
cupsdLogMessage(CUPSD_LOG_ERROR, "%s: Unable to create PPD for printer: %s", printer->name, strerror(errno));
ippDelete(response);
cupsFileClose(from);
return (NULL);
}
Expand All @@ -5431,6 +5433,8 @@ create_local_bg_thread(
else
cupsdLogMessage(CUPSD_LOG_ERROR, "%s: PPD creation failed: %s", printer->name, cupsLastErrorString());

ippDelete(response);

return (NULL);
}

Expand Down

0 comments on commit 4f154cb

Please sign in to comment.