<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - regression in cairo_surface_t refcounting when using cairo_surface_unmap_image"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=56981">56981</a>
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>chris@chris-wilson.co.uk
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>regression in cairo_surface_t refcounting when using cairo_surface_unmap_image
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>cairo-bugs@cairographics.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux (All)
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>richard@hughsie.com
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>1.12.8
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>general
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>cairo
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Using cairo 1.12.2 this code returns correctly with no warnings or errors:

//gcc -o cairo-test2 cairo-test2.c `pkg-config --cflags --libs cairo-pdf` &&
./cairo-test2
#include <glib.h>
#include <cairo.h>
int
main (int argc, char *argv[])
{
    cairo_surface_t *surface;
    cairo_surface_t *s2;
    surface = cairo_pdf_surface_create ("/tmp/dave.pdf", 300, 300);
    s2 = cairo_surface_map_to_image (surface, NULL);
    cairo_surface_unmap_image (surface, s2);
    cairo_surface_destroy (surface);
    return 0;
}

When testing with the more recent 1.12.8 I get:

cairo-test2: cairo-surface.c:930: cairo_surface_destroy: Assertion
`((*&(&surface->ref_count)->ref_count) > 0)' failed.

This can be worked around by doing something like this:

    cairo_surface_reference (surface); // <--- THIS SHOULD NOT BE REQUIRED!!!
    cairo_surface_unmap_image (surface, s2);

The documentation says: "The content of the image will be uploaded to the
target surface. Afterwards, the image is destroyed." It doesn't say anything
about unreffing the parent surface and this is quite unexpected.

Any help welcome, thanks.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>