4.20 AllocateMemory and invalid memory access

Just starting out? Need help? Post your questions and find answers here.
Marc
User
User
Posts: 28
Joined: Mon Jun 16, 2003 9:02 pm
Location: Paris - Villemer
Contact:

4.20 AllocateMemory and invalid memory access

Post by Marc »

I'm working on a IDE project using Scintilla
The following code report very often a Invalid Memory Access on the AllocateMemory function.
I also noticed:
- Same with 4.10
- No problem without the debugger

Any suggestion ?

Code: Select all

ProcedureDLL SciLexer_LoadFile(SciGadget.l, MyFile.s) ; Load the file MyFile

  Protected MyHandle.l
  Protected MyLen.l
  Protected *Mem.b

  Debug "Load " + MyFile

  SciLexer_ActionStatus = 1
  If FileSize(MyFile) > -1
    MyHandle = ReadFile(#PB_Any, MyFile)
    If MyHandle
      MyLen = Lof(MyHandle)
      Debug MyLen
      If MyLen > 0
        *Mem = AllocateMemory(MyLen + 1) ;Error at this line
        If *Mem
          ReadData(MyHandle, *Mem, MyLen)
          ScintillaSendMessage(SciGadget, #SCI_SETTEXT, 0,*Mem)
          FreeMemory(*Mem)         
        EndIf
      Else
        ScintillaSendMessage(SciGadget, #SCI_CLEARALL, 0, 0)
      EndIf
      CloseFile(MyHandle)      
    EndIf
  EndIf
  SciLexer_ActionStatus = 2

EndProcedure

Many thanks
Marc from PARIS - MVCOM Library
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

AllocateMemory() is not the problem (its a direct API call).
You have a heap corruption somewhere in your code.

Stick the _validate macro found in this post in your code in various places to narrow down where the error is:
http://www.purebasic.fr/english/viewtop ... 460#203460
quidquid Latine dictum sit altum videtur
Post Reply