Fix VB.NET unmanaged dll's not releasing memory (Libcairo)

Færdiggjort Opslået May 28, 2012 Betalt ved levering
Færdiggjort Betalt ved levering

This should be simple but its over my own head.

I have a function written in VB.NET that calls the libcairo dll's (<[url removed, login to view]>) to create a PDF file.

However the function or the dll's do not properly release their allocated memory after calling it, creating a huge memory leak.

I think this should be an easy task for someone familiar with making calls to unmanaged dlls or libcairo.

The affected module, in its entirety, is below. DLL's are attached.

## Deliverables

Imports System

Imports [url removed, login to view]

Imports [url removed, login to view]

Imports [url removed, login to view]

Imports [url removed, login to view]

Module PDF

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function SetDllDirectory(ByVal pathname As String) As Boolean

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Sub g_type_init()

End Sub

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function cairo_pdf_surface_create(ByVal file As String, ByVal width As Double, ByVal height As Double) As IntPtr

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function cairo_svg_surface_create(ByVal file As String, ByVal width As Double, ByVal height As Double) As IntPtr

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Sub cairo_surface_destroy(ByVal surface As IntPtr)

End Sub

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Sub cairo_destroy(ByVal surface As IntPtr)

End Sub

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Sub cairo_paint(ByVal surface As IntPtr)

End Sub

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Sub cairo_show_page(ByVal surface As IntPtr)

End Sub

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Sub cairo_set_source_surface(ByVal surface As IntPtr, ByVal img As IntPtr, ByVal x As Double, ByVal y As Double)

End Sub

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function cairo_create(ByVal surface As IntPtr) As IntPtr

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function rsvg_handle_new_from_file(ByVal file As String, ByVal [error] As String) As IntPtr

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function rsvg_handle_render_cairo(ByVal RsvgHandle As IntPtr, ByVal cairo_t As IntPtr) As [Boolean]

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function rsvg_handle_get_pixbuf(ByVal svg As IntPtr) As IntPtr

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function gdk_pixbuf_get_width(ByVal svg As IntPtr) As Integer

End Function

<DllImport("[url removed, login to view]", SetLastError:=True)> _

Private Function gdk_pixbuf_get_height(ByVal svg As IntPtr) As Integer

End Function

Public Sub Svg2PDF(ByVal inputFileName As String, ByVal outputFileName As String)

Dim callSuccessful As Boolean = SetDllDirectory([url removed, login to view])

If Not callSuccessful Then

Throw New Exception("Could not set DLL directory")

End If

[url removed, login to view]([url removed, login to view])

g_type_init()

Dim [error] As String = ""

Dim result As IntPtr = rsvg_handle_new_from_file(inputFileName, [error])

If Not [String].IsNullOrEmpty([error]) Then

Throw New Exception("Issue while loading SVG file!")

End If

Dim watermark As IntPtr = rsvg_handle_get_pixbuf(result)

' Get SVG size

Dim sw As Integer = gdk_pixbuf_get_width(watermark)

Dim sh As Integer = gdk_pixbuf_get_height(watermark)

' Create PDF

Dim surface As IntPtr = cairo_pdf_surface_create(outputFileName, sw, sh)

Dim img As IntPtr = cairo_svg_surface_create(Nothing, sw, sh)

Dim cr1 As IntPtr = cairo_create(img)

' Render SVG to surface

Dim result1 As [Boolean] = rsvg_handle_render_cairo(result, cr1)

Dim cr As IntPtr = cairo_create(surface)

' Poll PDF surface with SVG

cairo_set_source_surface(cr, img, 0, 0)

cairo_paint(cr)

cairo_show_page(cr)

cairo_destroy(cr)

cairo_surface_destroy(surface)

End Sub

End Module

.NET Script Installering Shell Script Visual Basic Windows Skrivebord

Projekt ID: #2745674

Om projektet

4 bud Remote projekt Aktiv May 28, 2012

Tildelt til:

ambrozija

See private message.

$20.4 USD in 14 dage
(72 bedømmelser)
6.8

4 freelancere byder i gennemsnit $49 timen for dette job

vano101

See private message.

$60 USD in 14 dage
(410 bedømmelser)
6.4
gkalish

See private message.

$63.75 USD in 14 dage
(116 bedømmelser)
5.7
tarikrital

See private message.

$63.75 USD in 14 dage
(25 bedømmelser)
5.5
renzondl

See private message.

$50.15 USD in 14 dage
(0 bedømmelser)
0.0