Memory leaks with ASL Library
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Hi.

    I found that any example of ASL library produces memory leaks when AslRequest() is called, maybe is my fault, but I have tried different examples, and all have the same problem, using MUI asl functions produces the same behaviour.

    This is one example found on the web:

    Code:

    ;/* filereq.c - Execute me to compile me with SASC 5.10
    LC -b1 -cfistq -v -y -j73 filereq.c
    Blink FROM LIB:c.o,filereq.o TO filereq LIBRARY LIB:LC.lib,LIB:Amiga.lib
    quit
    */
    #include <exec/types.h>
    #include <exec/libraries.h>
    #include <libraries/asl.h>
    #include <clib/exec_protos.h>
    #include <clib/asl_protos.h>
    #include <stdio.h>

    #ifdef LATTICE
    int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
    void chkabort(void) { return; } /* really */
    #endif

    UBYTE *vers = "$VER: filereq 37.0";

    #define MYLEFTEDGE 0
    #define MYTOPEDGE 0
    #define MYWIDTH 320
    #define MYHEIGHT 400

    struct Library *AslBase = NULL;

    struct TagItem frtags[] =
    {
    ASL_Hail, (ULONG)"The Amiga file requester",
    ASL_Height, MYHEIGHT,
    ASL_Width, MYWIDTH,
    ASL_LeftEdge, MYLEFTEDGE,
    ASL_TopEdge, MYTOPEDGE,
    ASL_OKText, (ULONG)"O KAY",
    ASL_CancelText, (ULONG)"not OK",
    ASL_File, (ULONG)"asl.library",
    ASL_Dir, (ULONG)"libs:",
    TAG_DONE
    };

    void main(int argc, char **argv)
    {
    struct FileRequester *fr;

    if (AslBase = OpenLibrary("asl.library", 37L))
    {
    if (fr = (struct FileRequester *)
    AllocAslRequest(ASL_FileRequest, frtags))
    {
    if (AslRequest(fr, NULL))
    {
    printf("PATH=%s FILE=%sn", fr->rf_Dir, fr->rf_File);
    printf("To combine the path and filename, copy the pathn");
    printf("to a buffer, add the filename with Dos AddPart().n");
    }
    FreeAslRequest(fr);
    }
    else printf("User Cancelledn");

    CloseLibrary(AslBase);
    }
    }


    Every time that this program is executed, the system memory doesn't recovers at all, every execution leaves less memory. Is this the normal behaviour?

    Here is the source and the executable file compiled with latest SDK and gcc 4.4.5.

    aslreq.lha
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »02.08.14 - 10:58
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    pegasos-sigi2
    Posts: 265 from 2006/8/31
    Try this source:

    int asl (char kopf[],BOOL save,STRPTR pattern,char dir_[150])
    {
    struct FileRequester *fr;
    unsigned char file[100] = "";
    unsigned char dir[100] = "";
    unsigned char path[100]= "";
    int filezahl = 0;

    AslBase = OpenLibrary("asl.library",40L);
    if (AslBase != NULL)
    {
    if( (fr = AllocAslRequestTags( ASL_FileRequest,
    ASL_Hail, (ULONG) kopf,
    ASL_OKText, (ULONG) "OK",
    ASL_CancelText, (ULONG) "Cancel",
    ASL_File, (ULONG) "",
    ASL_Dir, (ULONG) dir_,
    ASLFR_DoSaveMode,save,
    ASLFR_DoPatterns,TRUE,
    ASLFR_InitialPattern,pattern,
    TAG_DONE ) ) )
    {
    if (AslRequest(fr, NULL))
    {
    strcpy(file,fr->rf_File);
    strcpy(dir,fr->rf_Dir);
    strcat(path,dir);
    strcat(path,"/");
    strcat(path,file);
    strcpy(path2,path);

    if (strstr(path,":/") != 0)
    {
    unsigned char path[100] = "";
    strcat(path,dir);
    strcat(path,file);
    strcpy(path2,path);
    }
    }
    else
    {
    if (IoErr())
    {
    /*Es wird 0 in path2 kopiert, wenn man den Close-Button oder "Cancel" betätigt.*/
    strcpy(path2,"0");
    return 0;
    }
    else
    {
    /*Es wird 0 in path2 kopiert, wenn man den Close-Button oder "Cancel" betätigt.*/
    strcpy(path2,"0");
    return 0;
    }
    }
    FreeAslRequest(fr);
    }
    else
    {
    /* Es wird -1 in path2 kopiert, wenn man nicht die asl.library öffnen kann.*/
    strcpy(path2,"-1");
    return -1;
    }
    CloseLibrary(AslBase);
    }
    return 1;
    }



    The global variable path2 inhibit the selected path.





    Quote:

    BalrogSoft wrote:
    Hi.

    I found that any example of ASL library produces memory leaks when AslRequest() is called, maybe is my fault, but I have tried different examples, and all have the same problem, using MUI asl functions produces the same behaviour.

    This is one example found on the web:

    Code:

    ;/* filereq.c - Execute me to compile me with SASC 5.10
    LC -b1 -cfistq -v -y -j73 filereq.c
    Blink FROM LIB:c.o,filereq.o TO filereq LIBRARY LIB:LC.lib,LIB:Amiga.lib
    quit
    */
    #include <exec/types.h>
    #include <exec/libraries.h>
    #include <libraries/asl.h>
    #include <clib/exec_protos.h>
    #include <clib/asl_protos.h>
    #include <stdio.h>

    #ifdef LATTICE
    int CXBRK(void) { return(0); } /* Disable Lattice CTRL/C handling */
    void chkabort(void) { return; } /* really */
    #endif

    UBYTE *vers = "$VER: filereq 37.0";

    #define MYLEFTEDGE 0
    #define MYTOPEDGE 0
    #define MYWIDTH 320
    #define MYHEIGHT 400

    struct Library *AslBase = NULL;

    struct TagItem frtags[] =
    {
    ASL_Hail, (ULONG)"The Amiga file requester",
    ASL_Height, MYHEIGHT,
    ASL_Width, MYWIDTH,
    ASL_LeftEdge, MYLEFTEDGE,
    ASL_TopEdge, MYTOPEDGE,
    ASL_OKText, (ULONG)"O KAY",
    ASL_CancelText, (ULONG)"not OK",
    ASL_File, (ULONG)"asl.library",
    ASL_Dir, (ULONG)"libs:",
    TAG_DONE
    };

    void main(int argc, char **argv)
    {
    struct FileRequester *fr;

    if (AslBase = OpenLibrary("asl.library", 37L))
    {
    if (fr = (struct FileRequester *)
    AllocAslRequest(ASL_FileRequest, frtags))
    {
    if (AslRequest(fr, NULL))
    {
    printf("PATH=%s FILE=%sn", fr->rf_Dir, fr->rf_File);
    printf("To combine the path and filename, copy the pathn");
    printf("to a buffer, add the filename with Dos AddPart().n");
    }
    FreeAslRequest(fr);
    }
    else printf("User Cancelledn");

    CloseLibrary(AslBase);
    }
    }


    Every time that this program is executed, the system memory doesn't recovers at all, every execution leaves less memory. Is this the normal behaviour?

    Here is the source and the executable file compiled with latest SDK and gcc 4.4.5.

    aslreq.lha


    Spreedy - The spreedsheet editor of MorphOS
    Calimero - Do you know about the new DTP Program for MorphOS ?
  • »02.08.14 - 11:20
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    I have the same problem with your code, the system loses 50 kb approximately each execution.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »02.08.14 - 11:55
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    The problem with ASL Library is not only with this code. Any application that uses ASL library have the same problem, each call to AslRequest generate a memory leak of 50kb approx. even if cancel button is pressed, any system tool using ASL lib like FileImageCtrl have the same issue, it seems that it's not my fault, but is this a normal behaviour?

    [ Edited by BalrogSoft 04.08.2014 - 09:46 ]
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »04.08.14 - 10:40
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 3146 from 2003/3/5
    From: Canada
    50kB sounds bad for sure. I will have a look at what might be going on there...
  • »04.08.14 - 11:34
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 421 from 2003/2/24
    From: Berlin
    how do you measure the memory leak?


    [ Edited by igracki 04.08.2014 - 11:33 ]
  • »04.08.14 - 12:16
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    igracki
    Posts: 421 from 2003/2/24
    From: Berlin
    here it also leaks ~50kb!
    I used this script for measuring (with your example):
    Code:

    avail fast > env:m1
    r:aslrequest
    avail fast > env:m2

    rx "say $m1-$m2"
  • »04.08.14 - 12:33
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 3146 from 2003/3/5
    From: Canada
    Are you sure you don't have thumbnails in ASL enabled?
  • »04.08.14 - 14:53
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Quote:

    jacadcaps wrote:
    Are you sure you don't have thumbnails in ASL enabled?


    Thumbnails weren't used on my testings, all ASLcalls to AslRequest for a file requester produces a memory leak, Ambient preferences, MorphOS tools, Scribble, just open a file requester and close it, the system will lose 50kb.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »04.08.14 - 18:01
    Profile Visit Website
  • MorphOS Developer
    jacadcaps
    Posts: 3146 from 2003/3/5
    From: Canada
    Identified and fixed for 3.8. Thanks for reporting!
  • »04.08.14 - 20:14
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Quote:

    jacadcaps wrote:
    Identified and fixed for 3.8. Thanks for reporting!


    You're welcome, and thanks for your quick response, I can work with my code after know that it isn't the cause of this memory leak.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »05.08.14 - 23:46
    Profile Visit Website