[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/12/2004 at 03:44AM PST, ID: 21204506
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

OUT OF PRIVATE HANDLES

Asked by ragerino in C++ Programming Language

Tags: private, out, handles

i'm not very good on c++ and i got to develop a dll for our lotus domino server.
the problem i have is, when the dll is called about 1000 times the http-task of the domino server crashes whith following error message on the server console:
"MemAlloc: OUT OF PRIVATE HANDLES! -- pid 000004F4 Handles used so far 16953, Maximum handles = 10495"

here's the code of my dll
i think that my mistake is, that i use goto's when an error appears and i don't free the memory.

------------------------------------------------------------------------------------------------------------------
#include <stdlib.h>
#include <stdio.h>

// Lotus C API for Domino and Notes Header files.
#include <global.h>
#include <editods.h>
#include <osmem.h>
#include <schgtw.h>
#include <textlist.h>
#include <lapiplat.h>

// Header file.
#include "busytime2.h"
   

/************************************************************************
    DLL Main
*************************************************************************/
BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved){
    switch (ul_reason_for_call){
            case DLL_PROCESS_ATTACH:
            case DLL_THREAD_ATTACH:
            case DLL_THREAD_DETACH:
            case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}


/*************************************************************************
      Initializing Notes
*************************************************************************/
BUSYTIME_DLL_API int Start_Notes (char *exepath, char *inipath) {            
      STATUS sError;
      char *argv[2];
      //Umschlüsseln der Parameter
      argv[0] = exepath;
      argv[1] = inipath;
      //Notesinitialisierung
    sError = NotesInitExtended(2, argv);
      // Errorhandling
    if (sError != NOERROR) {
        LAPI_RETURN(2);
      } else {
        LAPI_RETURN(0);
      }
}


/*************************************************************************
      Wrapper function to exit from Domino and Notes.
*************************************************************************/


BUSYTIME_DLL_API void Stop_Notes (void) {
    NotesTerm();
}


/*************************************************************************
      Write Busytimes to File
*************************************************************************/
BUSYTIME_DLL_API int BusyTimeToFile (char *szUser, char *startTime, char *endTime, char *fname) {
      //Declarations
      char                  *theSchedList;
      int                        retcode=0;
      int                        laenge=0;
      int                        i;
      int                        anzuser=0;
      int                        anzschedules=0;
      char                  szMyUser[256]="";
      char                  *tmpUser=szUser;
      char                  *tmpStartTime;
      char                  *tmpEndTime;
      int                        zaehler=0;
      //Filepointers
      FILE                  *fz;
      //
      VOID                  *list_ptr;
      WORD                  list_size;
      DWORD                  retdwSize;
      //Notestypes
      STATUS                  sError = NOERROR;                  //typedef WORD STATUS;
      UNID                  apptUnid;                              //#define UNID UNIVERSALNOTEID
      HCNTNR                  schListCntnr = NULLHANDLE;      //typedef HANDLE HCNTNR; [ void LNPUBLIC SchContainer_Free(HCNTNR  hCntnr); ]
      HCNTNROBJ            schedObj;                              //typedef DWORD HCNTNROBJ;
      HCNTNROBJ            nextSchedObj;
      HCNTNROBJ            hMoreObj = NULLCNTNROBJ;
      TIMEDATE_PAIR      interval;                              //typedef struct {TIMEDATE Lower;TIMEDATE Upper;} TIMEDATE_PAIR;
      TIMEDATE_PAIR      pInterval;
      SCHEDULE            *nextSchedule;                        //typedef struct {DWORD reserved[8]; DBID dbReplicaID; TIMEDATE_PAIR Interval; DWORD dwErrGateway; STATUS error; WORD wReserved; WORD wOwnerNameSize; } SCHEDULE;
      SCHEDULE            *pSchedule;
      HANDLE                  list_handle;                        //typedef unsigned int HANDLE; [ OSMemAlloc / OSMemFree ]
      HANDLE                  rethSchedList;

      //try to open file
      if ((fz=fopen(fname,"w"))==NULL) {
            retcode=1;
            goto done;
      } else {
            sError = ListAllocate (0, 0, FALSE, &list_handle, &list_ptr, &list_size);
            if (sError != NOERROR)
                  goto NError;
            i=0;
            while (*tmpUser!='\0') {
                  if (i>=256) {
                        retcode=2;
                        goto done;
                  }
                  if(*tmpUser!=',') {
                        szMyUser[i++]=*tmpUser;
                  } else {
                        szMyUser[i++]='\0';
                        anzuser++;
                        sError = ListAddEntry(list_handle, FALSE, &list_size, (WORD) anzuser, szMyUser, (WORD) strlen(szMyUser));
                        if (sError != NOERROR)
                              goto NError;
                        i=0;
                  }
                  tmpUser++;
            }
            //add last user
            szMyUser[i]='\0';
            anzuser++;
            sError = ListAddEntry(list_handle, FALSE, &list_size, (WORD) anzuser, szMyUser, (WORD) strlen(szMyUser));
            if (sError != NOERROR)
                  goto NError;

            //Convert Start and Endtime to Notesdatetime
            tmpStartTime = startTime;
            tmpEndTime       = endTime;
            sError = ConvertTextToTIMEDATE(NULL, NULL, &tmpStartTime, (WORD) strlen(startTime), &interval.Lower);
            if (sError != NOERROR)
                  goto NError;
            sError = ConvertTextToTIMEDATE(NULL, NULL, &tmpEndTime, (WORD) strlen(endTime), &interval.Upper);
            if (sError != NOERROR)
                  goto NError;
            //Get Schedules
            OSUnlockObject(list_handle);
            list_ptr = OSLockObject(list_handle);
            sError = SchRetrieve(&apptUnid, NULL, SCHRQST_FORCEREMOTE|SCHRQST_EACHPERSON,&interval,(LIST *)list_ptr, &schListCntnr, NULL, NULL, NULL);  
            if (sError != NOERROR)
                  goto NError;
            
            // going through the schedules
            while (sError == NOERROR) {
                  zaehler++;
                  //beginn
                  if (anzschedules==0) {
                        // first schedule
                        sError = SchContainer_GetFirstSchedule(schListCntnr, &schedObj, &pSchedule);          
                        if (sError != NOERROR)
                              goto NError;
                        memcpy (szMyUser,pSchedule + 1 ,pSchedule->wOwnerNameSize);
                  }else {
                        // next schedule
                        sError = SchContainer_GetNextSchedule(schListCntnr, schedObj, &nextSchedObj, &nextSchedule);
                        if (sError != NOERROR)
                              goto NError;
                        schedObj=nextSchedObj;
                        memcpy (szMyUser,nextSchedule + 1 ,nextSchedule->wOwnerNameSize);
                  }
                  
                  //* extract the list
                  sError = Schedule_ExtractSchedList(      schListCntnr, schedObj, &pInterval, (unsigned long *) &retdwSize, &rethSchedList, &hMoreObj);
                  if (sError == NOERROR) {
                        anzschedules++;
                        fprintf(fz,"#\n");
                        fprintf(fz,"%s\n",szMyUser);
                        theSchedList=(char *)OSLockObject(rethSchedList);
                        // ... und in ein Stringarray hinzufügen
                        DumpTextSchedEntryListToFile(theSchedList,fz);
                        OSUnlockObject(rethSchedList);  
                  } else if (sError==1002 && zaehler<anzuser) {
                        sError=NO_ERROR;
                  }else {
                        goto NError;
                  }
            }

            //* Free all handles
            
            //OSUnlockObject(theSchedList);
            //OSMemFree(theSchedList);

            OSUnlockObject(list_handle);
            OSMemFree(list_handle);

            OSUnlockObject(rethSchedList);
            OSMemFree(rethSchedList);
      
            Schedule_Free(schListCntnr,schedObj);
            SchContainer_Free(schListCntnr);
      }
      
NError:
      retcode=0;
      if (sError!=NO_ERROR && sError!=1006 && sError!=1002) {
            retcode=2;
      } else if (anzuser!=anzschedules) {
            retcode=1;
      }
done:
      fclose(fz);
      LAPI_RETURN(retcode);
}

/************************************************************************
    FUNCTION:     DumpTextSchedEntryListToFile
*************************************************************************/
void LNPUBLIC DumpTextSchedEntryListToFile(char *pSchedList, FILE *fz) {
      //Declaration
      int                        num=0;
      int                        i=0;
      char                  szLowerTD[MAXALPHATIMEDATE+1];
      char                  szUpperTD[MAXALPHATIMEDATE+1];
      //Notesdatatypes
      SCHED_LIST            SchedList;            //typedef struct { DWORD NumEntries; WORD  wApplicationID; WORD Spare; } SCHED_LIST;
      SCHED_ENTRY            SchedEntry;            //typedef struct { UNID Unid; TIMEDATE_PAIR Interval; BYTE Attr; BYTE UserAttr; BYTE spare[2];} SCHED_ENTRY;

      
      memcpy( (char*)&SchedList, pSchedList, sizeof(SCHED_LIST) );
      pSchedList += sizeof(SCHED_LIST);
      num = SchedList.NumEntries;
      //fprintf(fz,"next\n");
      for (i=0;i<num;i++) {
            memcpy((char *)&SchedEntry, pSchedList, sizeof(SCHED_ENTRY) );
            //Check if busy
            if (SCHED_ATTR_AVAILABLE(SchedEntry.Attr)==FALSE) {
                  GetTDString( &(SchedEntry).Interval.Lower, szLowerTD );
                  GetTDString( &(SchedEntry).Interval.Upper, szUpperTD );
                  fprintf(fz,"%s-%s\n",szLowerTD,szUpperTD);
            }
            pSchedList += sizeof(SCHED_ENTRY);
      }

}

/************************************************************************
    FUNCTION:   GetTDString
*************************************************************************/
void LNPUBLIC GetTDString( TIMEDATE * ptdModified, char * szTimedate )
{
    WORD  wLen;
    ConvertTIMEDATEToText( NULL, NULL, ptdModified, szTimedate, MAXALPHATIMEDATE, &wLen );
    szTimedate[wLen] = '\0';
    return;
}
------------------------------------------------------------------------------------------------------------------
[+][-]11/12/04 04:08 AM, ID: 12564645

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: private, out, handles
Sign Up Now!
Solution Provided By: Axter
Participating Experts: 4
Solution Grade: A
 
 
[+][-]11/12/04 04:10 AM, ID: 12564651

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/04 04:10 AM, ID: 12564655

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/04 04:12 AM, ID: 12564668

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/04 04:12 AM, ID: 12564675

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/04 04:16 AM, ID: 12564699

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/12/04 04:21 AM, ID: 12564738

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/12/04 04:53 AM, ID: 12564963

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/04 04:57 AM, ID: 12565009

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11/12/04 04:58 AM, ID: 12565014

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12/04/04 01:55 PM, ID: 12745626

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12/20/04 04:42 PM, ID: 12872072

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]12/24/04 03:45 AM, ID: 12898675

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91