From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.42.148.65 with SMTP id q1mr7993455icv.28.1422856200796; Sun, 01 Feb 2015 21:50:00 -0800 (PST) X-Received: by 10.140.38.116 with SMTP id s107mr66942qgs.19.1422856200755; Sun, 01 Feb 2015 21:50:00 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!hl2no7153210igb.0!news-out.google.com!q4ni25qan.0!nntp.google.com!v8no5606416qal.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 1 Feb 2015 21:50:00 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.167.236.60; posting-account=bPTmZAoAAAC_6HP9XLKB9aAAxBa6BuOR NNTP-Posting-Host: 85.167.236.60 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Did I find mamory leak in Generic Image Decoder (GID) ? From: reinkor Injection-Date: Mon, 02 Feb 2015 05:50:00 +0000 Content-Type: text/plain; charset=ISO-8859-1 X-Received-Bytes: 5302 X-Received-Body-CRC: 758446196 Xref: news.eternal-september.org comp.lang.ada:24843 Date: 2015-02-01T21:50:00-08:00 List-Id: Dear All, I tried out GID (Generic Image Decoder) from http://sourceforge.net/projects/gen-img-dec/ The point was to read jpeg-images from my Ada program "wrapped" in a function: function read_jpg(cfile_jpg : String) return image1.imgc_t; The source code is below. However, this function seems to eat memory during (say 200) repeated calls to it (large images, 2000x1800 pixels each). I did something very very stupid ? reinert ---------------------------------------------------------------------- Here is the actual code: with Ada.Streams.Stream_IO; use Ada.Streams.Stream_IO; with Ada.Characters.Latin_1; with Interfaces.C; with Interfaces.C.Strings; with system; with Ada.Unchecked_Conversion; with Interfaces; with GID; with Ada.Calendar; with Ada.Characters.Handling; use Ada.Characters.Handling; with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Deallocation; with Text_IO; use Text_IO; package body file_handling3 is package Int_Io is new Text_IO.Integer_Io (Integer); use Int_Io; use Interfaces; type Byte_Array is array(Integer range <>) of Unsigned_8; type p_Byte_Array is access Byte_Array; procedure Dispose is new Ada.Unchecked_Deallocation(Byte_Array, p_Byte_Array); img_buf: p_Byte_Array := null; procedure Free_buf is new Ada.Unchecked_Deallocation(Object => Byte_Array, Name => p_Byte_Array); procedure Load_raw_image( image : in out GID.Image_descriptor; buffer: in out p_Byte_Array; next_frame: out Ada.Calendar.Day_Duration ) is subtype Primary_color_range is Unsigned_8; image_width : constant Positive:= GID.Pixel_Width(image); image_height: constant Positive:= GID.Pixel_height(image); idx: Natural; -- procedure Set_X_Y (x, y: Natural) is begin idx:= 3 * (x + image_width * (image_height - 1 - y)); end Set_X_Y; -- procedure Put_Pixel ( red, green, blue : Primary_color_range; alpha : Primary_color_range ) is pragma Warnings(off, alpha); -- alpha is just ignored begin buffer(idx..idx+2):= (red, green, blue); idx:= idx + 3; -- ^ GID requires us to look to next pixel on the right for next time. end Put_Pixel; stars: Natural:= 0; procedure Feedback(percents: Natural) is so_far: constant Natural:= percents / 5; begin for i in stars+1..so_far loop Put( Standard_Error, '*'); end loop; stars:= so_far; end Feedback; procedure Load_image is new GID.Load_image_contents( Primary_color_range, Set_X_Y, Put_Pixel, Feedback, GID.fast ); begin Dispose(buffer); buffer:= new Byte_Array(0..3 * image_width * image_height - 1); Load_image(image, next_frame); end Load_raw_image; function read_jpg(cfile_jpg : String) return image1.imgc_t is f: Ada.Streams.Stream_IO.File_Type; i: GID.Image_descriptor; name : String := cfile_jpg; up_name: constant String:= To_Upper(name); next_frame, current_frame: Ada.Calendar.Day_Duration:= 0.0; isx,isy : Integer; begin Open(f, In_File, name); GID.Load_image_header( i, Stream(f).all, try_tga => name'Length >= 4 and then up_name(up_name'Last-3..up_name'Last) = ".TGA" ); Load_raw_image(i, img_buf, next_frame); Close(f); isx := GID.Pixel_Width(i); isy := GID.Pixel_Height(i); New_line; Put(" isx,isy: ");Put(Integer'Image(isx));Put(Integer'Image(isy)); New_line; declare img1 : image1.imgc_t(1..isx,1..isy) := (others => (others => image1.Black)); Index : Positive; begin Index := img_buf'First; for j in img1'Range (2) loop for i in img1'Range (1) loop img1(i,isy - j + 1).red := image1.Short_I(img_buf (Index + 0)); img1(i,isy - j + 1).green := image1.Short_I(img_buf (Index + 1)); img1(i,isy - j + 1).blue := image1.Short_I(img_buf (Index + 2)); Index := Index + 3; end loop; end loop; Free_buf(img_buf); return img1; end; end read_jpg; end file_handling3;