]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Detach worker threads to prevent memory leaks.
authorMichael Sweet <michael.r.sweet@gmail.com>
Thu, 14 Sep 2017 18:19:00 +0000 (14:19 -0400)
committerMichael Sweet <michael.r.sweet@gmail.com>
Thu, 14 Sep 2017 18:19:00 +0000 (14:19 -0400)
test/ippserver.c

index 02dbdea50a8e710acd32670204fee4640018788a..38b304f80866206f5c05031ffa4f6a8faac0e314 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Sample IPP Everywhere server for CUPS.
  *
- * Copyright 2010-2015 by Apple Inc.
+ * Copyright 2010-2017 by Apple Inc.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
@@ -3763,6 +3763,7 @@ ipp_print_job(_ipp_client_t *client)      /* I - Client */
                        buffer[4096];   /* Copy buffer */
   ssize_t              bytes;          /* Bytes read */
   cups_array_t         *ra;            /* Attributes to send in response */
+  _cups_thread_t        t;              /* Thread */
 
 
  /*
@@ -3873,7 +3874,13 @@ ipp_print_job(_ipp_client_t *client)     /* I - Client */
   * Process the job...
   */
 
-  if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
+  t = _cupsThreadCreate((_cups_thread_func_t)process_job, job);
+
+  if (t)
+  {
+    _cupsThreadDetach(t);
+  }
+  else
   {
     job->state = IPP_JSTATE_ABORTED;
     respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
@@ -4180,17 +4187,7 @@ ipp_print_uri(_ipp_client_t *client)     /* I - Client */
   * Process the job...
   */
 
-#if 0
-  if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
-  {
-    job->state = IPP_JSTATE_ABORTED;
-    respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
-    return;
-  }
-
-#else
   process_job(job);
-#endif /* 0 */
 
  /*
   * Return the job info...
@@ -4382,17 +4379,7 @@ ipp_send_document(_ipp_client_t *client)/* I - Client */
   * Process the job...
   */
 
-#if 0
-  if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
-  {
-    job->state = IPP_JSTATE_ABORTED;
-    respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
-    return;
-  }
-
-#else
   process_job(job);
-#endif /* 0 */
 
  /*
   * Return the job info...
@@ -4751,17 +4738,7 @@ ipp_send_uri(_ipp_client_t *client)      /* I - Client */
   * Process the job...
   */
 
-#if 0
-  if (!_cupsThreadCreate((_cups_thread_func_t)process_job, job))
-  {
-    job->state = IPP_JSTATE_ABORTED;
-    respond_ipp(client, IPP_STATUS_ERROR_INTERNAL, "Unable to process job.");
-    return;
-  }
-
-#else
   process_job(job);
-#endif /* 0 */
 
  /*
   * Return the job info...
@@ -6828,7 +6805,13 @@ run_printer(_ipp_printer_t *printer)     /* I - Printer */
     {
       if ((client = create_client(printer, printer->ipv4)) != NULL)
       {
-       if (!_cupsThreadCreate((_cups_thread_func_t)process_client, client))
+        _cups_thread_t t = _cupsThreadCreate((_cups_thread_func_t)process_client, client);
+
+        if (t)
+        {
+          _cupsThreadDetach(t);
+        }
+        else
        {
          perror("Unable to create client thread");
          delete_client(client);
@@ -6840,7 +6823,13 @@ run_printer(_ipp_printer_t *printer)     /* I - Printer */
     {
       if ((client = create_client(printer, printer->ipv6)) != NULL)
       {
-       if (!_cupsThreadCreate((_cups_thread_func_t)process_client, client))
+        _cups_thread_t t = _cupsThreadCreate((_cups_thread_func_t)process_client, client);
+
+        if (t)
+        {
+          _cupsThreadDetach(t);
+        }
+        else
        {
          perror("Unable to create client thread");
          delete_client(client);