Fix VB.NET unmanaged dll's not releasing memory (Libcairo)
$30-75 USD
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
Projekt ID: #2745674