memory leak

This is a discussion on memory leak within the C++ Programming forums, part of the General Programming Boards category; can someone show me why does this programme eats my memeroy? thanks Code: #include "..includeLib_Clara.h" #include "..includeDir.h" #include "..includeutil.h" #include ...

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    1

    Unhappy memory leak

    can someone show me why does this programme eats my memeroy? thanks

    Code:
    #include "..includeLib_Clara.h"
    #include "..includeDir.h"
    #include "..includeutil.h"
    #include "..includestring.h"
    #include "..includemy_func.h"
    
    #define ADDSIZE 1
    #define BAGSIZE 7
    
    void onMyBookClose(BOOK *);
    void CloseMyBook(BOOK * Book, void *);
    int CreateMenu(void * r0, BOOK * bk);
    void kill(BOOK * book,void * lt);
    int UserInactivityEventEnabled=1;
    int CreateBookList();
    
    
    int ActiveTab=0;
    int files_count=0;
    int file_full=0;
    int file_rem=0;
    
    GUI_TABMENUBAR * tab=0;
    
    GUI_LIST * file_set2;
    GUI_LIST * file_set3;
    GUI_LIST * file_set4;
    GUI_LIST * file_set5;
    GUI_LIST * file_set1;
    
    int k=0;
    int focused_name=0;
    
    char f_set1[40][256];
    char f_set2[40][256];
    char f_set3[40][256];
    char f_set4[40][256];
    char f_set5[40][256];
    
    wchar_t * flash_folder = 0;
    wchar_t * swf = 0;
    wchar_t flash_name[128];
    wchar_t flash_name_disp[128];
    wchar_t swf_name[128];
    
    
    
    typedef struct
    {
    char *fname;
    wchar_t dir[512];
    int action;
    }FILELIST;
    
    
    BOOK* findbook(char* name)
    {
    int sesscount;
    BOOK * book;
    int sess,bk;
    UI_APP_SESSION * session;
    sesscount=root_list_get_session_count();
    for(sess=0;sess
    {
    session=root_list_get_session(sess);
    for (bk=0;bklistbook->FirstFree;bk++)
    {
    book=(BOOK*)ListElement_GetByIndex(session->listbook,bk);
    if(!strcmp(book->xbook->name,name))return book;
    }
    }
    return NULL;
    }
    
    
    typedef struct
    {
    BOOK book;
    void * oldOnKey;
    LIST * set1;
    LIST * set2;
    LIST * set3;
    LIST * set4;
    LIST * set5;
    }MyBOOK;
    
    typedef struct
    {
    BOOK * book;
    wchar_t *fname;
    int book_name;
    }BOOK_ITEM;
    
    int SubItem=0;
    
    typedef struct
    {
    LIST * book_list;
    int session_name;
    int book_in_session;
    wchar_t *fname;
    }SESSION_ITEM;
    
    typedef struct
    {
    BOOK * book;
    }MSG;
    
    
    MyBOOK * bman_book=0;
    MyBOOK * list_2=0;
    
    int Flash_Changer(BOOK * struc)
    {
    if (struc->onClose==(void*)onMyBookClose)
    {
    return(1);
    }
    else
    {
    return(0);
    }
    }
    
    
    void elf_exit(void)
    {
    kill_data(&ELF_BEGIN, (void(*)(void*))mfree_adr());
    }
    
    int onUserInactivity(void * r0, BOOK * bk)
    {
    if (UserInactivityEventEnabled) CloseMyBook(bk,0);
    return(0);
    };
    
    
    const PAGE_MSG MY_PageEvents[]@ "DYN_PAGE" ={
    USER_INACTIVITY_EVENT_TAG , onUserInactivity,
    NIL_EVENT_TAG,NULL
    };
    
    PAGE_DESC bk ={"MY_BasePage",0,MY_PageEvents};
    
    
    
    void CloseMyBook(BOOK * Book, void *)
    {
    MyBOOK * myBook=(MyBOOK*)Book;
    //SessoinListsFree(book);
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset1->FirstFree)
    {
    
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set1,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    
    }
    List_Free(myBook->set1);
    
    
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset2->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set2,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set2);
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset3->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set3,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set3);
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset4->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set4,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set4);
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset5->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set5,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set5);
    }
    FreeBook(Book);
    bman_book=0;
    };
    
    
    void onMyBookClose(BOOK * book)
    {
    MyBOOK * myBook=(MyBOOK*)book;
    //SessoinListsFree(book);
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset1->FirstFree)
    {
    
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set1,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    
    }
    List_Free(myBook->set1);
    //show_message(STR("onmybook"),2000);
    
    
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset2->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set2,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set2);
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset3->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set3,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set3);
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset4->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set4,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set4);
    }
    
    {
    int i=0;
    SESSION_ITEM *obj;
    while (iset5->FirstFree)
    {
    obj=(SESSION_ITEM*)ListElement_Remove(myBook->set5,i++);
    delete(obj->fname);
    TextFree(obj->session_name);
    delete(obj);
    }
    List_Free(myBook->set5);
    }
    
    }
    
    //==============================================================================
    
    void settings()
    {
    int file;
    FSTAT fstat;
    
    wchar_t * path = new wchar_t[wstrlen(GetDir(DIR_INI))+wstrlen((wchar_t*)L"/aruna1")+1];
    wstrcpy(path,GetDir(DIR_INI));
    wstrcat(path,(wchar_t*)L"/aruna1");
    
    if (isFileExist(path, (wchar_t*)L"Flash.ini", &fstat) == 0)
    {
    if ((file = _fopen(path, (wchar_t*)L"Flash.ini", 0x1, 0x180, 0)) >= 0)
    {
    char * buffer = new char[fstat.fsize + 1];
    buffer[fread(file, buffer, fstat.fsize)] = 0;
    char *param;
    
    
    if (param = manifest_GetParam(buffer, "[FLASH_MENU_FOLDER]", 0))
    {
    flash_folder = new wchar_t[strlen(param) + 1];
    str2wstr(flash_folder, param);
    mfree(param);
    }
    
    mfree(buffer);
    fclose(file);
    }
    }
    delete(path);
    }//end of reading ini file
    
    
    int read_theme_name()
    {
    int file;
    FSTAT fstat;
    wchar_t * theme = 0;
    
    
    if (isFileExist((wchar_t*)L"tpa/system/settings/",(wchar_t*)L"current_theme.thm.@", &fstat) == 0)
    {
    if ((file = _fopen((wchar_t*)L"tpa/system/settings/",(wchar_t*)L"current_theme.thm.@", 0x1, 0x180, 0)) >= 0)
    {
    theme=new wchar_t[SID_ANY_LEN];
    fread(file , theme, SID_ANY_LEN);
    fclose(file);
    }
    }
    
    wchar_t* fname1=0;
    fname1=wstrrchr(theme,'/');
    delete(theme);
    fname1++;
    wstrcpy(flash_name,fname1);
    wstrcpy(flash_name_disp,fname1);//name+ext
    wstrcpy(wstrrchr(flash_name,L'.'),_T(".swf"));
    wstrcpy(wstrrchr(flash_name_disp,L'.'),_T(""));
    
    return 0;
    }
    
    /*int current_flash_name()
    {
    int file;
    FSTAT fstat;
    
    wchar_t* pathx=0;
    
    pathx = new wchar_t[wstrlen(GetDir(DIR_INI))+wstrlen((wchar_t*)L"/aruna1/temp/flash_menu/")+1];
    wstrcpy(pathx,GetDir(DIR_INI));
    wstrcat(pathx,(wchar_t*)L"/aruna1/temp/flash_menu/");
    
    
    if (isFileExist(pathx,(wchar_t*)L"abc.txt", &fstat) == 0)
    {
    if ((file = _fopen(pathx,(wchar_t*)L"abc.txt", 0x1, 0x180, 0)) > 0)
    {
    //MessageBox (0x6fFFFFFF,STR( "test!"),0,1,2000,0);
    swfx=new wchar_t[SID_ANY_LEN];
    fread(file , swfx, SID_ANY_LEN);
    fclose(file);
    }
    //MessageBox (0x6fFFFFFF,Str2ID(swfx,1,15),0,1,2000,0);
    }
    
    wstrcpy(swf_name,swfx);
    wstrcpy(wstrrchr(swf_name,L'.'),_T(" "));
    
    delete(pathx);
    
    return 0;
    }*/
    
    int current_flash_name()
    {
    int file;
    FSTAT fstat;
    
    wchar_t* path=0;
    
    path = new wchar_t[wstrlen(GetDir(DIR_INI))+wstrlen((wchar_t*)L"/aruna1/temp/flash_menu/")+1];
    wstrcpy(path,GetDir(DIR_INI));
    wstrcat(path,(wchar_t*)L"/aruna1/temp/flash_menu/");
    
    //path==(wchar_t*)L"usb/other/ini/aruna1/temp/flash_menu/
    
    
    if (isFileExist(path,(wchar_t*)L"flash_menu.txt", &fstat) == 0)
    {
    if ((file = _fopen(path,(wchar_t*)L"flash_menu.txt", 0x1, 0x180, 0)) >= 0)
    {
    swf=new wchar_t[SID_ANY_LEN];
    fread(file , swf, SID_ANY_LEN);
    fclose(file);
    }
    }
    
    return 0;
    }
    
    
    
    
    //==============================================================================
    
    int file_count()
    {
    void * mem = malloc(0x300);
    void *handle=AllocDirHandle(flash_folder);
    
    FILELIST * flist2;
    
    
    while(flist2=(FILELIST *)GetFname(handle,mem))
    {
    files_count++;
    
    }
    
    file_full=files_count/40;
    file_rem=files_count%40;
    
    
    
    DestroyDirHandle(handle);
    mfree(mem);
    return(0);
    }
    
    
    
    
    void CreateBookLst(MyBOOK * myBook)
    {
    current_flash_name();
    
    
    
    void * mem = malloc(0x300);
    void *handle=AllocDirHandle(flash_folder);
    
    FILELIST * flist;
    
    int i=0,j;
    while(flist=(FILELIST *)GetFname(handle,mem))
    {
    
    if(i<=39)
    {
    {
    flist->fname=new char[512];
    
    for(j=0;j<=511;j++)
    {
    f_set1[i][j]=flist->fname[j];
    }
    
    }
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen((wchar_t*)f_set1[i])+ADDSIZE];
    wstrcpy(si->fname,(wchar_t*)f_set1[i]);
    ListElement_AddtoTop(myBook->set1,si);
    
    }
    
    if(i>39 && i<=79)
    {
    {
    flist->fname=new char[512];
    
    for(j=0;j<=511;j++)
    {
    f_set2[i-40][j]=flist->fname[j];
    }
    
    }
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen((wchar_t*)f_set2[i-40])+ADDSIZE];
    wstrcpy(si->fname,(wchar_t*)f_set2[i-40]);
    ListElement_AddtoTop(myBook->set2,si);
    }
    
    if(i>79 && i<=119)
    {
    {
    flist->fname=new char[512];
    
    for(j=0;j<=511;j++)
    {
    f_set3[i-80][j]=flist->fname[j];
    }
    
    }
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen((wchar_t*)f_set3[i-80])+ADDSIZE];
    wstrcpy(si->fname,(wchar_t*)f_set3[i-80]);
    ListElement_AddtoTop(myBook->set3,si);
    }
    
    if(i>119 && i<=159)
    {
    {
    flist->fname=new char[512];
    
    for(j=0;j<=511;j++)
    {
    f_set4[i-120][j]=flist->fname[j];
    }
    
    }
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen((wchar_t*)f_set4[i-120])+ADDSIZE];
    wstrcpy(si->fname,(wchar_t*)f_set4[i-120]);
    ListElement_AddtoTop(myBook->set4,si);
    }
    
    if(i>159 && i<=199)
    {
    {
    flist->fname=new char[512];
    
    for(j=0;j<=511;j++)
    {
    f_set5[i-160][j]=flist->fname[j];
    }
    
    }
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen((wchar_t*)f_set5[i-160])+ADDSIZE];
    wstrcpy(si->fname,(wchar_t*)f_set5[i-160]);
    ListElement_AddtoTop(myBook->set5,si);
    }
    
    i++;
    
    
    }
    
    /*{
    wchar_t *g1=(wchar_t*)L"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen(g1)+ADDSIZE];
    wstrcpy(si->fname,g1);
    ListElement_AddtoTop(myBook->set1,si);
    }
    
    
    {
    wstrcpy(swf_name,swf);
    wstrcpy(wstrrchr(swf_name,L'.'),_T(" "));
    
    wchar_t *g2=(wchar_t*)swf_name;
    SESSION_ITEM * si=new SESSION_ITEM;
    si->fname = new wchar_t[wstrlen(g2)+ADDSIZE];
    wstrcpy(si->fname,g2);
    ListElement_AddtoTop(myBook->set1,si);
    }*/
    
    
    
    DestroyDirHandle(handle);
    mfree(mem);
    k=i;
    //SetNumOfMenuItem(myBook->book.gui,(k+2));
    
    }
    
    int onLBMessage1(GUI_MESSAGE * msg)
    {
    MyBOOK * myBook = (MyBOOK *) FindBook(Flash_Changer);
    int item;
    SESSION_ITEM * si;
    switch(msg->msg)
    {
    case 1:
    item=GUIonMessage_GetCreatedItemIndex(msg);
    si=(SESSION_ITEM *)ListElement_GetByIndex(myBook->set1,item);
    SetMenuItemText0(msg,Str2ID(si->fname,0,100));
    SetMenuItemText2(msg,Str2ID (L"Flash Menu Changer by aruna1 nnnAruna Rubasinghennaruna.rubasinghe@gmail.comnn2008-06-14",0,100));
    }
    return(1);
    };
    
    
    int onLBMessage2(GUI_MESSAGE * msg)
    {
    MyBOOK * myBook = (MyBOOK *) FindBook(Flash_Changer);
    int item;
    SESSION_ITEM * si;
    switch(msg->msg)
    {
    case 1:
    item=GUIonMessage_GetCreatedItemIndex(msg);
    si=(SESSION_ITEM *)ListElement_GetByIndex(myBook->set2,item);
    SetMenuItemText0(msg,Str2ID(si->fname,0,100));
    SetMenuItemText2(msg,Str2ID (L"Flash Menu Changer by aruna1 nnnAruna Rubasinghennaruna.rubasinghe@gmail.comnn2008-06-14",0,100));
    }
    return(1);
    };
    
    int onLBMessage3(GUI_MESSAGE * msg)
    {
    MyBOOK * myBook = (MyBOOK *) FindBook(Flash_Changer);
    int item;
    SESSION_ITEM * si;
    switch(msg->msg)
    {
    case 1:
    item=GUIonMessage_GetCreatedItemIndex(msg);
    si=(SESSION_ITEM *)ListElement_GetByIndex(myBook->set3,item);
    SetMenuItemText0(msg,Str2ID(si->fname,0,100));
    SetMenuItemText2(msg,Str2ID (L"Flash Menu Changer by aruna1 nnnAruna Rubasinghennaruna.rubasinghe@gmail.comnn2008-06-14",0,100));
    }
    return(1);
    };
    
    int onLBMessage4(GUI_MESSAGE * msg)
    {
    MyBOOK * myBook = (MyBOOK *) FindBook(Flash_Changer);
    int item;
    SESSION_ITEM * si;
    switch(msg->msg)
    {
    case 1:
    item=GUIonMessage_GetCreatedItemIndex(msg);
    si=(SESSION_ITEM *)ListElement_GetByIndex(myBook->set4,item);
    SetMenuItemText0(msg,Str2ID(si->fname,0,100));
    SetMenuItemText2(msg,Str2ID (L"Flash Menu Changer by aruna1 nnnAruna Rubasinghennaruna.rubasinghe@gmail.comnn2008-06-14",0,100));
    }
    return(1);
    };
    
    int onLBMessage5(GUI_MESSAGE * msg)
    {
    MyBOOK * myBook = (MyBOOK *) FindBook(Flash_Changer);
    int item;
    SESSION_ITEM * si;
    switch(msg->msg)
    {
    case 1:
    item=GUIonMessage_GetCreatedItemIndex(msg);
    si=(SESSION_ITEM *)ListElement_GetByIndex(myBook->set5,item);
    SetMenuItemText0(msg,Str2ID(si->fname,0,100));
    SetMenuItemText2(msg,Str2ID (L"Flash Menu Changer by aruna1 nnnAruna Rubasinghennaruna.rubasinghe@gmail.comnn2008-06-14",0,100));
    }
    return(1);
    };
    
    
    void onEnterPressed(BOOK * book,void * lt)
    {
    //focused_name=((k+2)-(GetFocusetListObjectItem(book->gui)+1));
    //MessageBox (0x6fFFFFFF,STR( "test!"),0,1,2000,0);
    int tab_number=TabMenuBar_GetFocusedTabIndex(tab);
    
    if(tab_number==0)
    {
    if(tab_number
    focused_name=(39-(GetFocusetListObjectItem(file_set1)));
    else
    focused_name=(file_rem-1-(GetFocusetListObjectItem(file_set1)));
    }
    
    if(tab_number==1)
    {
    if(tab_number
    focused_name=(39-(GetFocusetListObjectItem(file_set2)));
    else
    focused_name=(file_rem-1-(GetFocusetListObjectItem(file_set2)));
    }
    
    if(tab_number==2)
    {
    if(tab_number
    focused_name=(39-(GetFocusetListObjectItem(file_set3)));
    else
    focused_name=(file_rem-1-(GetFocusetListObjectItem(file_set3)));
    }
    
    if(tab_number==3)
    {
    if(tab_number
    focused_name=(39-(GetFocusetListObjectItem(file_set4)));
    else
    focused_name=(file_rem-1-(GetFocusetListObjectItem(file_set4)));
    }
    
    wchar_t ws[193];
    snwprintf(ws, 193, (wchar_t*)L"tab %d file %d",tab_number,focused_name);
    MessageBox (0x6fFFFFFF,Str2ID(ws,0,193),0,1,2000,0);
    
    
    int *erro=0;
    {
    FileDelete(flash_folder,swf, erro);
    }
    
    {
    int file;
    FSTAT fstat;
    //FSTAT fstat2;
    int size;
    char *buf;
    
    
    
    int file3;
    wchar_t* path=0;
    
    path = new wchar_t[wstrlen(GetDir(DIR_INI))+wstrlen((wchar_t*)L"/aruna1/temp/flash_menu/")+1];
    wstrcpy(path,GetDir(DIR_INI));
    wstrcat(path,(wchar_t*)L"/aruna1/temp/flash_menu/");
    
    
    if ((file3=_fopen(path,(wchar_t*)L"flash_menu.txt",0x204,0x180,0))>=0)
    {
    
    if(tab_number==0)
    {
    fwrite(file3,(char*)f_set1[focused_name], 256);
    
    {
    if ((file=_fopen(flash_folder,(wchar_t*)f_set1[focused_name],0x001,0x180,0))>=0)
    {
    if (isFileExist(flash_folder,(wchar_t*)f_set1[focused_name],&fstat)==0)
    {
    buf=(char*)malloc(fstat.fsize+1);
    size=fstat.fsize;
    fread(file,buf,fstat.fsize);
    }
    fclose(file);
    }
    
    
    int file2;
    if ((file2=_fopen(flash_folder,(wchar_t*)flash_name,0x204,0x180,0))>=0)
    {
    fwrite(file2,(char*)buf, size);
    mfree(buf);
    fclose(file2);
    }
    }
    
    }
    
    if(tab_number==1)
    {
    fwrite(file3,(char*)f_set2[focused_name], 256);
    
    {
    if ((file=_fopen(flash_folder,(wchar_t*)f_set2[focused_name],0x001,0x180,0))>=0)
    {
    if (isFileExist(flash_folder,(wchar_t*)f_set2[focused_name],&fstat)==0)
    {
    buf=(char*)malloc(fstat.fsize+1);
    size=fstat.fsize;
    fread(file,buf,fstat.fsize);
    }
    fclose(file);
    }
    
    
    int file2;
    if ((file2=_fopen(flash_folder,(wchar_t*)flash_name,0x204,0x180,0))>=0)
    {
    fwrite(file2,(char*)buf, size);
    mfree(buf);
    fclose(file2);
    }
    }
    
    }
    
    if(tab_number==2)
    {
    fwrite(file3,(char*)f_set3[focused_name], 256);
    {
    if ((file=_fopen(flash_folder,(wchar_t*)f_set3[focused_name],0x001,0x180,0))>=0)
    {
    if (isFileExist(flash_folder,(wchar_t*)f_set3[focused_name],&fstat)==0)
    {
    buf=(char*)malloc(fstat.fsize+1);
    size=fstat.fsize;
    fread(file,buf,fstat.fsize);
    }
    fclose(file);
    }
    
    
    int file2;
    if ((file2=_fopen(flash_folder,(wchar_t*)flash_name,0x204,0x180,0))>=0)
    {
    fwrite(file2,(char*)buf, size);
    mfree(buf);
    fclose(file2);
    }
    }
    
    }
    
    if(tab_number==3)
    {
    fwrite(file3,(char*)f_set4[focused_name], 256);
    
    {
    if ((file=_fopen(flash_folder,(wchar_t*)f_set4[focused_name],0x001,0x180,0))>=0)
    {
    if (isFileExist(flash_folder,(wchar_t*)f_set4[focused_name],&fstat)==0)
    {
    buf=(char*)malloc(fstat.fsize+1);
    size=fstat.fsize;
    fread(file,buf,fstat.fsize);
    }
    fclose(file);
    }
    
    
    int file2;
    if ((file2=_fopen(flash_folder,(wchar_t*)flash_name,0x204,0x180,0))>=0)
    {
    fwrite(file2,(char*)buf, size);
    mfree(buf);
    fclose(file2);
    }
    }
    
    }
    
    if(tab_number==4)
    {
    fwrite(file3,(char*)f_set5[focused_name], 256);
    
    {
    if ((file=_fopen(flash_folder,(wchar_t*)f_set5[focused_name],0x001,0x180,0))>=0)
    {
    if (isFileExist(flash_folder,(wchar_t*)f_set5[focused_name],&fstat)==0)
    {
    buf=(char*)malloc(fstat.fsize+1);
    size=fstat.fsize;
    fread(file,buf,fstat.fsize);
    }
    fclose(file);
    }
    
    
    int file2;
    if ((file2=_fopen(flash_folder,(wchar_t*)flash_name,0x204,0x180,0))>=0)
    {
    fwrite(file2,(char*)buf, size);
    mfree(buf);
    fclose(file2);
    }
    }
    
    }
    fclose(file3);
    }
    delete(path);
    
    
    //kill(FindBook(Flash_Changer),0);
    //CreateBookList();
    }
    };
    
    /*GUI_LIST * CreateGuiList(void * r0, BOOK * bk)
    {
    GUI_LIST * file_set1;
    
    file_set1 =CreateListObject(bk,0);
    bk->gui=(GUI*)file_set1;
    
    GuiObject_SetTitleText(file_set1,(STR("Select Flash Menu")));
    CreateBookLst((MyBOOK*)bk);
    
    OneOfMany_SetonMessage((GUI_ONEOFMANY*)file_set1,(void*)onLBMessage);
    SetCursorToItem(file_set1,2);
    SetMenuItemStyle(file_set1,0);
    
    AddMSGHook(file_set1,ACTION_BACK, kill);
    AddMSGHook(file_set1,ACTION_SELECT1,onEnterPressed);
    AddMSGHook(file_set1,1,kill);
    AddCommand(file_set1,1,STR("Exit"));
    
    return(file_set1);
    };*/
    
    
    
    
    
    GUI_TABMENUBAR * CreateGuiList(void * r0, BOOK * bk)
    {
    file_set1 =CreateListObject(bk,0);
    file_set2 =CreateListObject(bk,0);
    file_set3 =CreateListObject(bk,0);
    file_set4 =CreateListObject(bk,0);
    file_set5 =CreateListObject(bk,0);
    
    bk->gui=(GUI*)file_set2;
    CreateBookLst((MyBOOK*)bk);
    
    
    wstrcpy(swf_name,swf);
    wstrcpy(wstrrchr(swf_name,L'.'),_T(" "));
    /*wchar_t * set1=(wchar_t*)L"set1: ";
    wstrcat(set1,(wchar_t*)swf_name);
    int len=wstrlen(set1)+1;*/
    
    
    //===============================================================
    
    //GuiObject_SetTitleText(file_set1,Str2ID(p,5,2));
    {
    //wchar_t * set1=(wchar_t*)L"set1: ";
    //wstrcat(set1,(wchar_t*)swf_name);
    //int len1=wstrlen(set1)+1;
    
    GuiObject_SetTitleText(file_set1,(STR("Set1")));
    OneOfMany_SetonMessage((GUI_ONEOFMANY*)file_set1,onLBMessage1);
    SetCursorToItem(file_set1,0);
    SetNumOfMenuItem(file_set1,40);
    
    AddMSGHook(file_set1,ACTION_BACK, kill);
    AddMSGHook(file_set1,ACTION_SELECT1,onEnterPressed);
    AddCommand(file_set1,1,STR("About"));
    }
    
    //=================================================================
    
    {
    //wchar_t * set2=(wchar_t*)L"set2: ";
    //wstrcat(set2,(wchar_t*)swf_name);
    //int len2=wstrlen(set2)+1;
    
    //GuiObject_SetTitleText(file_set2,Str2ID(set2,0,len2));
    GuiObject_SetTitleText(file_set2,(STR("Set2")));
    SetCursorToItem(file_set2,0);
    OneOfMany_SetonMessage((GUI_ONEOFMANY*)file_set2,onLBMessage2);
    SetNumOfMenuItem(file_set2,40);
    
    
    AddMSGHook(file_set2,ACTION_BACK, kill);
    AddMSGHook(file_set2,ACTION_SELECT1,onEnterPressed);
    AddCommand(file_set2,1,STR("About"));
    }
    
    //============================================================
    
    {
    //wchar_t * set3=(wchar_t*)L"set3: ";
    //wstrcat(set3,(wchar_t*)swf_name);
    //int len3=wstrlen(set3)+1;
    
    //GuiObject_SetTitleText(file_set3,Str2ID(set3,0,len3));
    GuiObject_SetTitleText(file_set3,(STR("Set3")));
    SetCursorToItem(file_set3,0);
    OneOfMany_SetonMessage((GUI_ONEOFMANY*)file_set3,onLBMessage3);
    SetNumOfMenuItem(file_set3,40);
    
    
    AddMSGHook(file_set3,ACTION_BACK, kill);
    AddMSGHook(file_set3,ACTION_SELECT1,onEnterPressed);
    AddCommand(file_set3,1,STR("About"));
    }
    
    //=============================================================
    
    {
    //wchar_t * set4=(wchar_t*)L"set4: ";
    //wstrcat(set4,(wchar_t*)swf_name);
    //int len4=wstrlen(set4)+1;
    
    //GuiObject_SetTitleText(file_set4,Str2ID(set4,0,len4));
    GuiObject_SetTitleText(file_set4,(STR("Set4")));
    SetCursorToItem(file_set4,0);
    OneOfMany_SetonMessage((GUI_ONEOFMANY*)file_set4,onLBMessage4);
    SetNumOfMenuItem(file_set4,20);
    
    
    AddMSGHook(file_set4,ACTION_BACK, kill);
    AddMSGHook(file_set4,ACTION_SELECT1,onEnterPressed);
    AddCommand(file_set4,1,STR("About"));
    }
    
    //================================================================
    
    {
    //wchar_t * set5=(wchar_t*)L"set5: ";
    //wstrcat(set5,(wchar_t*)swf_name);
    //int len5=wstrlen(set5)+1;
    
    //GuiObject_SetTitleText(file_set5,Str2ID(set5,0,len5));
    GuiObject_SetTitleText(file_set5,(STR("Set5")));
    SetCursorToItem(file_set5,0);
    OneOfMany_SetonMessage((GUI_ONEOFMANY*)file_set5,onLBMessage5);
    SetNumOfMenuItem(file_set5,40);
    
    
    AddMSGHook(file_set5,ACTION_BACK, kill);
    AddMSGHook(file_set5,ACTION_SELECT1,onEnterPressed);
    AddCommand(file_set5,1,STR("About"));
    }
    
    //===============================================================
    
    int tabs=0,x=0;
    {
    if(file_rem>0)
    {
    x=1;
    }
    else
    {
    x=0;
    }
    
    tabs=file_full+x;
    }
    
    tab = CreateTabMenuBar(bk);
    TabMenuBar_SetTabCount(tab,tabs);
    TabMenuBar_SetTabFocused(tab,0);
    TabMenuBar_AssignGuiObj(tab,0,file_set1);
    TabMenuBar_AssignGuiObj(tab,1,file_set2);
    TabMenuBar_AssignGuiObj(tab,2,file_set3);
    TabMenuBar_AssignGuiObj(tab,3,file_set4);
    TabMenuBar_AssignGuiObj(tab,4,file_set5);
    
    //TabMenuBar_SetTabIcon(tab,0,dyn_image[0].ImageID,0);
    //TabMenuBar_SetTabIcon(tab,0,dyn_image[1].ImageID,1);
    
    //TabMenuBar_SetTabIcon(tab,1,dyn_image[2].ImageID,0);
    //TabMenuBar_SetTabIcon(tab,1,dyn_image[3].ImageID,1);
    
    return(tab);
    };
    
    
    
    int CreateMenu(void * r0, BOOK * bk)
    {
    bk->gui=(GUI*)CreateGuiList(0,bk);
    ShowWindow(bk->gui);
    return(0);
    }
    
    __root int CreateBookList()
    {
    if (!bman_book)
    {
    MyBOOK * myBook =bman_book= (MyBOOK *)malloc(sizeof(MyBOOK));
    memset(myBook,0,sizeof(MyBOOK));
    CreateBook(myBook,onMyBookClose,&bk,"Flash Changer GUI",-1,0);
    myBook->set1=List_New();
    myBook->set2=List_New();
    myBook->set3=List_New();
    myBook->set4=List_New();
    myBook->set5=List_New();
    CreateMenu(0,(BOOK*)bman_book);
    
    }
    return(0);
    }
    
    void kill(BOOK * book,void * lt)
    {
    ;
    
    delete(flash_folder);
    FreeBook(book);
    SUBPROC(elf_exit);
    }
    int main()
    {
    settings();
    bman_book=0;
    file_count();
    read_theme_name();
    CreateBookList();
    
    return(0);
    }

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Nobody is going to go through all that especially since it's not even indented.
    Just check to make sure all the malloc() calls are matched with a free()

  3. #3
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,183
    If you are using Linux, try valgrind (a memory debugger/leak detector).

    Someone please recommend the equivalent for Windows?

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,609
    You should add that source file as an attachment. Script is a lot easier to read when it's properly indented.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leak in this case?
    By George2 in forum C++ Programming
    Replies: 3
    Last Post: 03-22-2008, 05:05 AM
  2. memory leak in the code?
    By George2 in forum C++ Programming
    Replies: 20
    Last Post: 01-13-2008, 05:50 AM
  3. Is this code memory leak free? ---> POSIX Threads
    By avalanche333 in forum C++ Programming
    Replies: 9
    Last Post: 04-13-2007, 03:19 PM
  4. Any Memory Leak Checking Tool?
    By George2 in forum C Programming
    Replies: 4
    Last Post: 06-21-2006, 11:02 PM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21