[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

973.0. "malloc -> XtFree memory mixup?" by ASD::DIGRAZIA () Mon Jun 19 1989 10:49

	We have code that allocates memory using malloc, and
	frees the same memory using XtFree.

	Is it ok to mix malloc and XtFree calls, or ought
	we use malloc/free or XtCalloc/XtFree consistently?

	The symptom we see is that after XtFree-ing some malloc'd
	memory, the next call to malloc returns a 0, but we know we 
	haven't run out of memory.

	Regards, Robert.

T.RTitleUserPersonal
Name
DateLines
973.1RAB::DESAIJatin DesaiMon Jun 19 1989 11:219
>	Is it ok to mix malloc and XtFree calls, or ought
>	we use malloc/free or XtCalloc/XtFree consistently?

    I believe you can not mix-n-match malloc/XtMalloc and free/XtFree.
    You must use the right (matching) one.

Jatin

973.2While we're on the subject,POOL::HALLYBThe Smart Money was on GoliathMon Jun 19 1989 16:268
    Can one use LIB$GET_VM on VMS systems as well as *alloc/*free ?
    Presuming, of course, the "free" routine corresponds to the "get"
    routine.
    
    Can be important when combining existing code into DW applications.
    
      John

973.3Sure canEVETPU::REINIGThis too shall changeMon Jun 19 1989 16:305
    Sure can.  TPU uses LIB$GET_VM.  Since it calls the toolkit, it also
    uses *alloc/*free.  FAKE_VM helps with all of this.
    
                                    August G. Reinig

973.4difference?BUFFER::RITTOThu Jun 22 1989 11:126
   What's the difference between using malloc and XtMalloc?  Is
   there a reason to use one over the other?

   Confused, but thankful,
   Pat

973.5CASEE::LACROIXGone with the windThu Jun 22 1989 11:4216
>   What's the difference between using malloc and XtMalloc?  Is
>   there a reason to use one over the other?

    In general, XtMalloc/XtFree is supposed to be a lot faster than
    malloc/free in the C RTL. But the most important things is that some of
    the stuff you have XtMalloced maybe later XtFreed or XtRealloced by
    some toolkit code, or by some code you have stolen somewhere. XtFreeing
    something that was malloced is potentially a serious problem. The rules
    would be something like: when you are doing DECwindows programming, UI
    stuff, use XtMalloc/XtFree (or XMalloc/XFree...), and whenever you are
    interfacing with something else, THINK A LOT. It is very easy to shoot
    yourself in the foot. And yes, FAKE_VM is absolutely GREAT for memory
    corruptions (and you will have some).

    Denis.

973.6Cheap plug for FAKE_VMDDIF::BRAMHALLMark Bramhall, CDA architectureTue Jun 27 1989 17:047
    A cheap plug for FAKE_VM...
    
    FAKE_VM remembers the allocation method (LIB$GET_VM, malloc, XtMalloc,
    etc.) and will tell you if you are freeing the allocated memory with a
    different method.  Freeing with a different method is one of the surest
    ways to totally corrupt your memory!

973.7For us, I found trivial causeGRANDE::DIGRAZIAWed Jul 05 1989 12:3017
	Speaking of sure ways to corrupt memory, I entered the base
	note because we had semi-reproducible explosions in our code,
	which we decided were caused by something haywire in our
	dynamic-memory stuff.

	We knew we had a few malloc/XtFree combinations, etc.

	But it turns out that I found some simple, old-fashioned
	overruns in one of our modules.  (I found a strcpy moving 
	too-long strings into malloc'd memory, thereby overwriting 
	malloc's bookkeeping words.)

	Many thanks for assistance.

	Regards, Robert.