• Welcome, Guest. Please login.
 
July 04, 2020, 02:53:01 pm

News:

Welcome to the SQLitening support forums!


Error Code 7 A malloc() failed

Started by Fim, April 01, 2020, 05:02:06 am

Previous topic - Next topic

Fim

In my system, I handle all processing of a Sql database via a special IO module, a module for each table. Everything works as I had imagined. But in a special case I get error code 7. I have done some tests and it seems I do NOT get error if I make all SQL calls directly in a program without going through an io module.
I get the error after 3732 calls with function GU (get unique).

FUNKTION_GU:
'===========
'
GU_SELECT:
    slOpen TRIM$(KOM.DATABAS)
    SET_NUMMER = slGetUnusedSetNumber
    SEL_STRANG = "SELECT * FROM ART WHERE ARTNR= " + $SQ + TRIM$(ART.ARTNR) + $SQ
    SVAR = slSel(SEL_STRANG, SET_NUMMER) ' Ska ge noll
    IF SVAR <>  0 THEN
        KOM.FELTEXT = "SYSTEMFEL i ARTIO GU slSel=" + STR$(SVAR)  <<============
        GOTO SYSTEMFELHANTERING
        EXIT SUB
    END IF

Tips where to look for errors are gratefully received.
/Fim W.



Fim W

Fim

After a few changes to my program, everything works as it should. Which of the changes that corrected the error I do not know.
Fim W

cj

May 09, 2020, 06:41:43 pm #2 Last Edit: May 09, 2020, 09:37:28 pm by cj
Quote from: undefinedIn my system, I handle all processing of a Sql database via a special IO module, a module for each table. Everything works as I had imagined. But in a special case I get error code 7. I have done some tests and it seems I do NOT get error if I make all SQL calls directly in a program without going through an io module.
I get the error after 3732 calls with function GU (get unique).
Searching for SQLITE_NOMEM and it shows out of memory or something of that nature.
It could be an array out of bounds or passing nothing.

slGetUsedSetNumber (never needed it.)

The opening of the database from a udt memory might be it if the value is "".
That would open a temporary table without returning an error to you with perhaps no data to process.

Might be running out of memory if the recordsets are not processed until the end (or slSetClose was needed.)
' Process records of Set 1  (example in the help file)
Do While slGetRow(1)
' check the value of field 3   
  if slF(3, 1) >= "AB100" then Exit Do
Loop
slCloseSet(1)

https://www.sqlite.org/search?s=d&q=SQLITE_NOMEM


REM #define SQLITE_NOMEM        7  /* A malloc() failed */

cj

May 11, 2020, 09:36:20 am #3 Last Edit: May 11, 2020, 10:22:28 am by cj
Fim,

I was able to get an error 7 by calling slOpen 1000's of times.
Looking at task manager the memory use went over a billion bytes.

Calling slOpen multiple times without slClose before reopening would be my first guess at the problem.
This would corect it:
IF ISFALSE(slIsOpen) THEN slOpen "Mydatabase.db3"

Test program that demonstrates a global handle is created each time slOpen is called.
https://sqlitening.planetsquires.com/index.php?topic=9760.msg26646#msg26646


This program demonstrates getting an error 7. 
If you run task manager before starting this you will see the memory usage go sky high.

GLOBAL gs AS STRING
#INCLUDE "sqlitening.inc"

FUNCTION PBMAIN () AS LONG
slSetProcessMods "E2"
LOCAL x AS LONG
Logit "Open database only if not open"
FOR x = 1 TO 5
  IF ISFALSE(slIsOpen) THEN slopen "junk.tmp","C": Logit USING$("handle #",slGetHandle)
NEXT
slClose
KILL "junk.tmp"
Logit  ERROR$(ERR) + " killing junk.tmp"

Logit ""
Logit "Open database without testing if already open"
FOR x = 1 TO 32000
  slopen "junk.tmp","C"
  IF x MOD 1000 = 0 THEN Logit USING$("#",slGetHandle)
NEXT
slClose
KILL "junk.tmp"
LOGIT ERROR$(ERR) + " killing junk.tmp"

? gs

END FUNCTION

SUB LogIt(s AS STRING)
gs = gs + s
END SUB