Details Ticket 4246


Comment | Reply | Take | Resolve


Serial Number 4246
Subject NVIZ: Memory allocated by Tcl must be freed using Tcl_Free
Area grass6
Queue grass
Requestors hamish_nospam@yahoo.com
Owner none
Status open
Last User Contact Thu May 25 19:40:31 2006 (2 yr ago)
Current Priority 30
Final Priority 70
Due No date assigned
Last Action Mon Oct 16 05:24:54 2006 (2 yr ago)
Created Wed Apr 5 11:58:14 2006 (2 yr ago)

Transaction History Ticket 4246


Wed, Apr 5 2006 11:58:14    Request created by guest  
Subject: NVIZ: segfault in kanimation panel

(latest 6.1-CVS)

If you open NVIZ, go to the Keyframe Animation panel, unclick the "FromX" on
box, and click "Add", NVIZ segfaults. 

If it makes it past the FromX "Add", try turning off FromY, "Add", FromZ,
"Add", .. it always breaks by then for me.


Also if I save a keyframe animation then reload it (maybe change the frame
rate, add a keyframe, or other modifications and resave) I get consistent
segfaults and weird corrupted error messages when I pass the mouse over the
"Draw" button near the top.

I notice when a new frame is added, and the dark blue vertical bar is all the
way to the far right, the light blue key frame gets updated but the black
current time doesn't get updated until you move the dark blue slider. ?


thanks,
Hamish
Wed, Apr 5 2006 12:09:38    User changed to hamish_nospam@yahoo.com by msieczka  
Fri, Apr 7 2006 07:46:58    Mail sent by hbowman  
> If you open NVIZ, go to the Keyframe Animation panel, unclick the "FromX" on
> box, and click "Add", NVIZ segfaults. 
>
> If it makes it past the FromX "Add", try turning off FromY, "Add", FromZ,
> "Add", .. it always breaks by then for me.

this is 6.1-cvs compiled with tcltk 8.4-dev on Debian/stable (sarge) by the way.
> Also if I save a keyframe animation then reload it (maybe change the frame
> rate, add a keyframe, or other modifications and resave) I get consistent
> segfaults and weird corrupted error messages when I pass the mouse over the
> "Draw" button near the top.

maybe related: "nviz -q" to start then load a .kanim setup file and it
segfaults. Maybe trying to move the camera without expanding the bounds of the
known universe?


also another segfault:  (maybe same issue?)
Make a script file with d.nviz, then:
 nviz script=file.nvscr 
and it segfaults quite quickly. I get a message after the segfault that it
created the .kanim file (-k) but I see none.

If you do 
 nviz script=badfilename

NVIZ will start ok after giving you an error message that it couldn't find the
file.

In 6.0.2 (compiled with tcltk 8.3-dev) it works ok.


thanks,
Hamish
Sat, Apr 8 2006 13:10:46    Mail sent by hbowman  
re. segfault in nviz if you use a d.nviz generated script:

G61> nviz script=somefile.nvsrc


The segfaults happens when it tries to add a keyframe:

visualization/nviz/src/anim_support.c
line ~410 in  Nadd_key_cmd()

   G_free (listels);

if I comment that line out, the script runs, nviz loads, and all is good.

printf(%p) shows listels at 0xbfffee6c

I notice in the compiler warnings:
anim_support.c:367: warning: passing arg 4 of `Tcl_SplitList' from
incompatible pointer type

which is this:
    if (Tcl_SplitList(interp, argv[2], &numels, &listels) != TCL_OK)

is that call promoting listels to something else?


Is there a better way of debugging nviz than just peppering puts and printf's?
gdb is useless for it.


thanks,
Hamish
Sat, Apr 8 2006 13:21:43    Comments added by hbowman  
Commenting that G_free() fixes both the FromX and load script segfaults.


Hamish
Tue, Apr 11 2006 15:09:22    Mail sent by bcovill@tekmap.ns.ca  
Return-Path <bcovill@tekmap.ns.ca>
Delivered-To grass-bugs@lists.intevation.de
Date Tue, 11 Apr 2006 10:08:25 -0300
From Bob Covill <bcovill@tekmap.ns.ca>
Subject Re: [GRASS5] [bug #4246] (grass) NVIZ: segfault in kanimation panel
In-reply-to <20060408111046.BCF6E1006CA@lists.intevation.de>
To Harmish Bowman via RT <grass-bugs@intevation.de>, Hamish <hamish_nospam@yahoo.com>
Cc GRASS Develope <grass5@grass.itc.it>
Message-id <1144760905.10072.8.camel@linuxmain.localhost>
MIME-version 1.0
X-Mailer Evolution 2.4.0
Content-type text/plain
Content-transfer-encoding 7BIT
X-BrightmailFiltered true
X-Brightmail-Tracker AAAAAQAAA+k=
References <20060408111046.BCF6E1006CA@lists.intevation.de>
X-Spam-Status No, hits=-4.9 tagged_above=-999.0 required=3.0 tests=BAYES_00
X-Spam-Level
Hamish,

I took a quick look at this and I cannot duplicate the error. I do get
the compiler warning for all of the Tcl_SplitList in src. According to
TCL recent documentation arg 4 in Tcl_SplitList should actually be
"const char **". If I change 
char **listels;
in anim_support.c (line ~933)
to const char **listels;
I do not get the compiler warning.

Also, according to the Tcl_SplitList documentation, the **listels
argument should be freed. They recommend using 
Tcl_Free((char *) argv);

I am not sure why the free call would be creating a problem. 

Hope this helps.

--
Bob

On Sat, 2006-04-08 at 13:10 +0200, Harmish Bowman via RT wrote:
> re. segfault in nviz if you use a d.nviz generated script:
> 
> G61> nviz script=somefile.nvsrc
> 
> 
> The segfaults happens when it tries to add a keyframe:
> 
> visualization/nviz/src/anim_support.c
> line ~410 in  Nadd_key_cmd()
> 
>    G_free (listels);
> 
> if I comment that line out, the script runs, nviz loads, and all is good.
> 
> printf(%p) shows listels at 0xbfffee6c
> 
> I notice in the compiler warnings:
> anim_support.c:367: warning: passing arg 4 of `Tcl_SplitList' from
> incompatible pointer type
> 
> which is this:
>     if (Tcl_SplitList(interp, argv[2], &numels, &listels) != TCL_OK)
> 
> is that call promoting listels to something else?
> 
> 
> Is there a better way of debugging nviz than just peppering puts and printf's?
> gdb is useless for it.
> 
> 
> thanks,
> Hamish
> 
> 
> -------------------------------------------- Managed by Request Tracker
> 
> _______________________________________________
> grass5 mailing list
> grass5@grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass5
> 


Wed, Apr 12 2006 05:07:41    Mail sent by hamish_nospam@yahoo.com  
Return-Path <hamish_nospam@yahoo.com>
Delivered-To grass-bugs@lists.intevation.de
Date Wed, 12 Apr 2006 15:07:21 +1200
From Hamish <hamish_nospam@yahoo.com>
To Bob Covill <bcovill@tekmap.ns.ca>
Cc grass-bugs@intevation.de, grass5@grass.itc.it
Subject Re: [GRASS5] [bug #4246] (grass) NVIZ: segfault in kanimation panel
Message-Id <20060412150721.30236da7.hamish_nospam@yahoo.com>
In-Reply-To <1144760905.10072.8.camel@linuxmain.localhost>
References <20060408111046.BCF6E1006CA@lists.intevation.de> <1144760905.10072.8.camel@linuxmain.localhost>
X-Mailer Sylpheed version 1.0.4 (GTK+ 1.2.10; i386-pc-linux-gnu)
X-Face M<EoB)"*Z~u!,vFhXmw}R_KbdBta*P_=T|rbBL'e1/CQ9;/1g\BU3&!=y8ria$2Uk!HT&BB 8i?|X_+7~1jsy}F~g$2va%3fV`*=L(*cem[@3\yg,G,@rg6/QMJ
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Spam-Status No, hits=-4.0 tagged_above=-999.0 required=3.0 tests=BAYES_00, FORGED_YAHOO_RCVD
X-Spam-Level
> I took a quick look at this and I cannot duplicate the error.

I am using Debian with TclTk 8.4, which is a new thing. See:
  http://article.gmane.org/gmane.comp.gis.grass.devel/11177
  http://grass.itc.it/pipermail/grass-commit/2006-March/021104.html

Maybe a similar issue?

(I haven't recompiled with tcltk 8.3 yet to check if this is the case,
obviously it would be a good idea to do so. It works fine with a CVS
version from February (compiled with tcltk 8.3), so I would guess this 
is a pretty strong lead)


> I do get the compiler warning for all of the Tcl_SplitList in src.
> According to TCL recent documentation arg 4 in Tcl_SplitList should
> actually be "const char **". If I change 
> char **listels;
> in anim_support.c (line ~933)
> to const char **listels;
> I do not get the compiler warning.

If I add "const", the warning goes away for me too. But it still
segfaults on Load anim file.

I also notice these warnings:

<command line>:5:1: warning: "__STDC__" redefined
In file included from anim_support.c:11:
interface.h:363: warning: `struct Map_info' declared inside parameter list
interface.h:363: warning: its scope is only this definition or declaration, which
is probably not what you want


and eight "warning: passing arg 1 of `...' as `float' rather than `double' due
to prototype"

 
> Also, according to the Tcl_SplitList documentation, the **listels
> argument should be freed. They recommend using 
> Tcl_Free((char *) argv);
> 
> I am not sure why the free call would be creating a problem. 

see above links ??



I've made a number of small cleanups to the kanim code in the last week
to make things a little easier on the user (also d.nviz, nviz2.2_script).
Hopefully it will just be smoother and the changes won't be noticed. 
The Keyframe Animator help page is extended including an example and 
should be easier to follow.

Also I added an #ifdef to the MPEG code to make it easy to switch to
using the XVID codec. (compile with gcc -D"USE_XVID") This should really
be an enviro var or GIS var setting, but for now it's a quick proof of 
concept hack.

Result of this is that making movies is somewhat easier now. Great 
synergy with r.in.wms(x2) or r.in.onearth scripts to fetch SRTM and 
LANDSAT. Process LANDSAT image with Markus's i.landsat.rgb & even 
better.


Q: If I make a track with d.nviz the camera looks straight down, not
forwards along the track. Is this normal/expected?



cheers,
Hamish


Tue, Apr 18 2006 07:18:54    Comments added by hbowman  
[Reply from Bob posted to the grass5 mailing list]


From: Bob Covill <bcovill tekmap ns ca>
Cc: GRASS Develope <grass5 grass itc it>
Subject: Re: [GRASS5] [bug #4246] (grass) NVIZ: segfault in kanimation panel
Date: Wed, 12 Apr 2006 10:29:19 -0300
To: Hamish <hamish_nospam yahoo com>

On Wed, 2006-04-12 at 15:07 +1200, Hamish wrote:
> > I took a quick look at this and I cannot duplicate the error.
> 
> I am using Debian with TclTk 8.4, which is a new thing. See:
>   http://article.gmane.org/gmane.comp.gis.grass.devel/11177
>   http://grass.itc.it/pipermail/grass-commit/2006-March/021104.html
> 
> Maybe a similar issue?
> 
> (I haven't recompiled with tcltk 8.3 yet to check if this is the case,
> obviously it would be a good idea to do so. It works fine with a CVS
> version from February (compiled with tcltk 8.3), so I would guess this 
> is a pretty strong lead)
> 
> 
> > I do get the compiler warning for all of the Tcl_SplitList in src.
> > According to TCL recent documentation arg 4 in Tcl_SplitList should
> > actually be "const char **". If I change 
> > char **listels;
> > in anim_support.c (line ~933)
> > to const char **listels;
> > I do not get the compiler warning.
> 
> If I add "const", the warning goes away for me too. But it still
> segfaults on Load anim file.
> 
> I also notice these warnings:
> 
> <command line>:5:1: warning: "__STDC__" redefined
> In file included from anim_support.c:11:
> interface.h:363: warning: `struct Map_info' declared inside parameter list
> interface.h:363: warning: its scope is only this definition or declaration,
which is probably not what you want
> 
> 
> and eight "warning: passing arg 1 of `...' as `float' rather than `double'
due to prototype"

I also get these warnings?

>  
> > Also, according to the Tcl_SplitList documentation, the **listels
> > argument should be freed. They recommend using 
> > Tcl_Free((char *) argv);
> > 
> > I am not sure why the free call would be creating a problem. 
> 
> see above links ??

Taking a look at some of the other Tcl_SplitList calls (for example in
draw.c) the char is freed with G_free ((char *) ...). I would expect
these to also segfault if it was a problem with G-free. Try simply
changing 
G_free (listels);
to 
G_free ((char *) listels);

> 
> 
> 
> I've made a number of small cleanups to the kanim code in the last week
> to make things a little easier on the user (also d.nviz, nviz2.2_script).
> Hopefully it will just be smoother and the changes won't be noticed. 
> The Keyframe Animator help page is extended including an example and 
> should be easier to follow.

These all sound great. The extended help is a good idea as the Keyframe
Animator can be quite difficult to learn.

> 
> Also I added an #ifdef to the MPEG code to make it easy to switch to
> using the XVID codec. (compile with gcc -D"USE_XVID") This should really
> be an enviro var or GIS var setting, but for now it's a quick proof of 
> concept hack.

Instead of a compile flag could we try something like ...
codec = avcodec_find_encoder(CODEC_ID_XVID);
if (!codec)
{
	codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
	if (!codec) {
		fprintf(stderr, "codec not found\n");
		return(-1);
	}
}
This way it tries to load the better quality codec, and if it fails it
will load the old standard mpeg1. I have not tested it to see if it
works. 

> 
> Result of this is that making movies is somewhat easier now. Great 
> synergy with r.in.wms(x2) or r.in.onearth scripts to fetch SRTM and 
> LANDSAT. Process LANDSAT image with Markus's i.landsat.rgb & even 
> better.
> 
> 
> Q: If I make a track with d.nviz the camera looks straight down, not
> forwards along the track. Is this normal/expected?

If the camera is looking down then you need to increase the dist
parameter. The combination of the ht and dist parameters are what
determine the camera look angle. 

> 
> 
> 
> cheers,
> Hamish
> 

Hope this helps.

--
Bob
Tue, Apr 18 2006 07:21:03    Comments added by hbowman  
> > I am using Debian with TclTk 8.4, which is a new thing. See:
> >   http://article.gmane.org/gmane.comp.gis.grass.devel/11177
> >   http://grass.itc.it/pipermail/grass-commit/2006-March/021104.html
> > 
> > Maybe a similar issue?
..
> > > I do get the compiler warning for all of the Tcl_SplitList in src.
> > > According to TCL recent documentation arg 4 in Tcl_SplitList
> > > should actually be "const char **". If I change 
> > > char **listels;
> > > in anim_support.c (line ~933)
> > > to const char **listels;
> > > I do not get the compiler warning.
> > 
> > If I add "const", the warning goes away for me too. But it still
> > segfaults on Load anim file.
> > 
> > I also notice these warnings:
> > 
> > <command line>:5:1: warning: "__STDC__" redefined
> > In file included from anim_support.c:11:
> > interface.h:363: warning: `struct Map_info' declared inside
> > parameter list interface.h:363: warning: its scope is only this
> > definition or declaration, which is probably not what you want


> > > Also, according to the Tcl_SplitList documentation, the **listels
> > > argument should be freed. They recommend using 
> > > Tcl_Free((char *) argv);
> > > 
> > > I am not sure why the free call would be creating a problem. 
> > 
> > see above links ??
> 
> Taking a look at some of the other Tcl_SplitList calls (for example in
> draw.c) the char is freed with G_free ((char *) ...). I would expect
> these to also segfault if it was a problem with G-free. Try simply
> changing 
> G_free (listels);
> to 
> G_free ((char *) listels);

Nope, still segfaults.



> > Also I added an #ifdef to the MPEG code to make it easy to switch to
> > using the XVID codec. (compile with gcc -D"USE_XVID") This should
> > really be an enviro var or GIS var setting, but for now it's a quick
> > proof of  concept hack.
> 
> Instead of a compile flag could we try something like ...
> codec = avcodec_find_encoder(CODEC_ID_XVID);
> if (!codec)
> {
> 	codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
> 	if (!codec) {
> 		fprintf(stderr, "codec not found\n");
> 		return(-1);
> 	}
> }
> This way it tries to load the better quality codec, and if it fails it
> will load the old standard mpeg1. I have not tested it to see if it
> works. 

Maybe someone wants something more than XVID or MPEG-1?
 (shrug- anybody?)

XVID requires the canvas to be some multiple of 16x16, and fails to
load (without telling why) or produces artifacts in the output if not. 
So as a default it may be tricky for newcomers.. But most/all other
encoders have the same problem. (including MPEG-1??)


> > Q: If I make a track with d.nviz the camera looks straight down, not
> > forwards along the track. Is this normal/expected?
> 
> If the camera is looking down then you need to increase the dist
> parameter. The combination of the ht and dist parameters are what
> determine the camera look angle. 

Oh, ok. I was keeping dist= small as I was getting out-of-region
messages and skipped points if I went within that distance to the edge
of the region. Any thoughts on extending the module to work with a
vector line? Maybe needs a cat= option tp pick specific line and a -r
reverse flag to follow it the other direction. I'm thinking flying above
a road or weaking the flight path in v.digit.


Hamish
Thu, May 25 2006 19:40:31    Mail sent by guest  
Bob hit the nail on the head. Memory allocated by Tcl must be freed by
Tcl_Free. It can't be freed by glibc (G_free).

The reason for this is that newer versions of Tcl incorporate special memory
management. Tcl allocates big chunks of memory using malloc, then doles out
smaller pieces of memory when Tcl_Alloc is called inside other parts of Tcl.
I fixed this occurane in anim_support.c and commited it to CVS.

We need someone who is familiar with the NVIZ code to hunt down other improper
uses of G_free and glibc free before closing this bug.
Fri, May 26 2006 10:19:18    Mail sent by hamish_nospam@yahoo.com  
Return-Path <hamish_nospam@yahoo.com>
Delivered-To grass-bugs@lists.intevation.de
Date Fri, 26 May 2006 20:19:00 +1200
From Hamish <hamish_nospam@yahoo.com>
To Cedric Shock <cedricgrass@shockfamily.net>
Cc grass-dev@grass.itc.it, glynn@gclements.plus.com, michael.barton@asu.edu, grass-bugs@intevation.de
Subject Re: [bug #4246] [GRASS-dev] Memory freeing errors in NVIZ
Message-Id <20060526201900.3a1ce7e3.hamish_nospam@yahoo.com>
In-Reply-To <200605251100.33804.cedricgrass@shockfamily.net>
References <20060525071518.14d0dc00.hamish_nospam@yahoo.com> <C09A00F9.21B14%michael.barton@asu.edu> <20060525181259.4a0a5786.hamish_nospam@yahoo.com> <200605251100.33804.cedricgrass@shockfamily.net>
X-Mailer Sylpheed version 1.0.4 (GTK+ 1.2.10; i386-pc-linux-gnu)
X-Face M<EoB)"*Z~u!,vFhXmw}R_KbdBta*P_=T|rbBL'e1/CQ9;/1g\BU3&!=y8ria$2Uk!HT&BB 8i?|X_+7~1jsy}F~g$2va%3fV`*=L(*cem[@3\yg,G,@rg6/QMJ
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Spam-Status No, hits=-4.0 tagged_above=-999.0 required=3.0 tests=BAYES_00, FORGED_YAHOO_RCVD
X-Spam-Level
Cedric:
> I just fixed your keyframe bug in CVS. I didn't close the bug because
> it mentions other pieces of the nviz code that do the same thing
> (something about draw.c).

Yes, it all seems to work ok now, great!

It didn't work for me earier - I guess I just added "(char *)" but must
have left the G_free()s in place?? Hmph. No matter, it is working now.


what about the "const"?

Bob: [from the bug report]
> I do get the compiler warning for all of the Tcl_SplitList in src.
> According to TCL recent documentation arg 4 in Tcl_SplitList should
> actually be "const char **". If I change 
> char **listels;
> in anim_support.c (line ~933)
> to const char **listels;
> I do not get the compiler warning.


Cedric:
> Memory allocated by Tcl must be freed using Tcl_Free. This is the same
> thing that was the nviz segfault on startup bug. Tcl 8.4 is the first
> version that takes advantage of tcl's memory management abstraction,
> which has been in place since at least 7.0. Tcl_Alloc and Tcl_Free
> just happened to be malloc an free on all platforms before 8.4. I
> know I've said this before, but it bears repeating.

repetition helps


Glynn:
> My guess is that the Debian package uses threads while the FC4 version
> doesn't. FWIW, my version was built without thread support.

Debian's 8.4 uses threads. This would explain why the Mandrake version
failed too.



thanks,
Hamish


Sat, May 27 2006 06:57:58    Comments added by hbowman  
[copied from -dev list]

Cedric:
> If there isn't anything else important in 4246, go ahead and close it
> if this  fixed it for you. 
> 
> I checked and fixed frees related to every occurrence of Tcl_SplitList
> since  its easy to find. It's also used to set the second argument of
> Ngetargs, so I  followed it as well (it never gets freed).
> 
> This command run in the nviz directory generates a huge list of other
> things that could be checked:
> 
> fgrep -n Tcl_ *.c | fgrep -v Tcl_Interp | fgrep -v Tcl_Get | \
>   fgrep -v Tcl_Free | fgrep -v Tcl_SetResult | fgrep -v \
>   Tcl_CreateCommand | fgrep -v Tcl_SplitList


The only reason to keep the bug open is if that fgrep list has
many probables, not just possibles. The bug can be renamed....


Hamish
Tue, Aug 29 2006 04:11:59    Subject changed to NVIZ: Memory allocated by Tcl must be freed using Tcl_Free by hbowman  
Tue, Sep 26 2006 18:36:23    Comments added by guest  
Good Luck! http://xoomer.alice.it/pik0/poker-rooms/
Tue, Sep 26 2006 22:41:05    Comments added by guest  
Cool design http://xoomer.alice.it/pik0/razz-poker/
Wed, Sep 27 2006 01:26:09    Comments added by guest  
Great work on website. <a href="http://xoomer.alice.it/pik0/rules-of-poker/">rules
of poker</a> [url=http://xoomer.alice.it/pik0/rules-of-poker/]rules of poker[/url]
http://xoomer.alice.it/pik0/rules-of-poker/
Mon, Oct 16 2006 05:24:54    Comments added by hbowman  
This bug contains SPAM.


Hamish
Comment | Reply | Take | Resolve

You are currently authenticated as guest.
[Show Configuration] [Login as another user]

Users Guide - Mail Commands - Homepage of RequestTracker 1.0.7 - list any request