/** * Deallocates JVM context */ STATIC void JVM_Free(JVM * jvm) { if (jvm) { if (jvm->hModule) FreeLibrary(jvm->hModule); MEM_Free(jvm->versionString); MEM_Free(jvm->javaHome); MEM_Free(jvm->javaLib); MEM_Free(jvm); } }
/** * Initializes the output zlib context */ STATIC Bool ZipInitOut(Zip * zf) { /* allocate buffer */ zf->outbuf = (I8u*)MEM_Alloc(zf->bufsize); if (zf->outbuf) { /* allocate zlib context */ zf->out = MEM_New(z_stream); if (zf->out) { int zerr; int bits = ((zf->zflags & ZIP_ZHDR) ? (-MAX_WBITS) : MAX_WBITS); /* tell zlib to use our memory allocation functions */ memset(zf->out, 0, sizeof(*zf->out)); zf->out->zalloc = ZipMemAlloc; zf->out->zfree = ZipMemFree; /* windowBits is passed < 0 to suppress zlib header */ zerr = deflateInit2(zf->out, Z_BEST_COMPRESSION, Z_DEFLATED, bits, 8, Z_DEFAULT_STRATEGY); if (zerr == Z_OK) { if (zf->zflags & ZIP_GZIP) { /* write a very simple .gz header */ I8u hdr[10]; memset(hdr, 0, sizeof(hdr)); hdr[0] = (I8u)GzMagic[0]; hdr[1] = (I8u)GzMagic[1]; hdr[2] = Z_DEFLATED; hdr[9] = OS_CODE; if (FILE_Write(zf->f,hdr,sizeof(hdr)) == sizeof(hdr)) { FILE_Flush(zf->f); zf->out->next_out = zf->outbuf; zf->out->avail_out = zf->bufsize; return True; } } else { /* not writing the header */ zf->out->next_out = zf->outbuf; zf->out->avail_out = zf->bufsize; return True; } deflateEnd(zf->out); } MEM_Free(zf->out); zf->out = NULL; } MEM_Free(zf->outbuf); zf->outbuf = NULL; } zf->zflags |= ZIP_OUT_ERR; return False; }
/** * Puts work item to the global pool or deallocates it. Also deallocates * the events associated with the work item. NOTE: this code is designed * to be efficient, not compact */ STATIC void WKQ_ReleaseWorkItem(WorkQueueModule * module, WorkItem * w) { Bool locked = False; ASSERT(module->initcount > 0); ASSERT(!w->submitQ.queue); ASSERT(!w->itemsQ.queue); /* deallocate waiters */ while (w->waiters) { Waiter * waiter = w->waiters; Waiter * next = waiter->next; if (module->nwait < module->maxwait) { if (locked) { WKQ_WaiterToPool(module, waiter); waiter = NULL; } else { locked = MUTEX_Lock(&module->mutex); if (module->nwait < module->maxwait) { WKQ_WaiterToPool(module, waiter); waiter = NULL; } } } if (waiter) { EVENT_Destroy(&waiter->event); MEM_Free(waiter); } w->waiters = next; } if (QUEUE_Size(&module->itempool) < module->maxitems) { if (locked) { w->flags = WKI_DETACHED; QUEUE_InsertTail(&module->itempool, &w->itemsQ); } else { locked = MUTEX_Lock(&module->mutex); if (QUEUE_Size(&module->itempool) < module->maxitems) { w->flags = WKI_DETACHED; QUEUE_InsertTail(&module->itempool, &w->itemsQ); } else { MEM_Free(w); } } } else { MEM_Free(w); } if (locked) { MUTEX_Unlock(&module->mutex); } }
/** * Creates MidpSession for the specified XRPC client id. Invoked on the XRPC * thread under synchronization. */ STATIC MidpSession* GWENG_MidpCreateSession(EcmtGateway* gw, int xrpcSid) { MidpSession* ses = MEM_New(MidpSession); if (ses) { LUID luid; /* Just in case if AllocateLocallyUniqueId fails... */ luid.LowPart = (DWORD)ses; AllocateLocallyUniqueId(&luid); memset(ses, 0, sizeof(*ses)); ses->key.xrpcSid = xrpcSid; ses->key.xrpcSession = XRPC_GetCurrentSession(gw->xrpc); ses->sid = luid.LowPart; ASSERT(!HASH_Contains(&gw->ecmtSessionMap,(HashKey)ses->sid)); ASSERT(!HASH_Contains(&gw->midpSessionMap,&ses->key)); if (HASH_Init(&ses->connMap, 1, NULL, NULL, hashFreeValueProc)) { /* Create context for the control connection (number zero) */ MidpConnection* conn = MEM_New(MidpConnection); if (conn) { memset(conn, 0, sizeof(*conn)); if (HASH_Put(&ses->connMap, (HashKey)0, conn)) { if (HASH_Put(&gw->ecmtSessionMap,(HashKey)ses->sid,ses)) { if (HASH_Put(&gw->midpSessionMap, &ses->key, ses)) { if (MUTEX_Init(&ses->xrpcMutex)) { ses->xrpcWorkThread = WKQ_Create(); if (ses->xrpcWorkThread) { ses->xrpcWorkItem = WKI_Create( ses->xrpcWorkThread, GWENG_AsyncXRpc, ses); if (ses->xrpcWorkItem) { QUEUE_Init(&ses->xrpcQueue); TRACE3("GW: new session %08x for " "%08x.%08x\n", ses->sid, ses->key.xrpcSession, ses->key.xrpcSid); return ses; } WKQ_Delete(ses->xrpcWorkThread); } MUTEX_Destroy(&ses->xrpcMutex); } HASH_Remove(&gw->midpSessionMap, &ses->key); } HASH_Remove(&gw->ecmtSessionMap, (HashKey)ses->sid); } } else { MEM_Free(conn); } } HASH_Destroy(&ses->connMap); } MEM_Free(ses); } return NULL; }
/* * ======== freeBlock ======== * TO DO: freeBlock() allocates memory, which could result in failure. * Could allocate an RMM_Header in RMM_alloc(), to be kept in a pool. * freeBlock() could use an RMM_Header from the pool, freeing as blocks * are coalesced. */ static bool freeBlock(struct RMM_TargetObj *target, u32 segid, u32 addr, u32 size) { struct RMM_Header *head; struct RMM_Header *thead; struct RMM_Header *rhead; bool retVal = true; /* Create a memory header to hold the newly free'd block. */ rhead = MEM_Calloc(sizeof(struct RMM_Header), MEM_PAGED); if (rhead == NULL) { retVal = false; } else { /* search down the free list to find the right place for addr */ head = target->freeList[segid]; if (addr >= head->addr) { while (head->next != NULL && addr > head->next->addr) head = head->next; thead = head->next; head->next = rhead; rhead->next = thead; rhead->addr = addr; rhead->size = size; } else { *rhead = *head; head->next = rhead; head->addr = addr; head->size = size; thead = rhead->next; } /* join with upper block, if possible */ if (thead != NULL && (rhead->addr + rhead->size) == thead->addr) { head->next = rhead->next; thead->size = size + thead->size; thead->addr = addr; MEM_Free(rhead); rhead = thead; } /* join with the lower block, if possible */ if ((head->addr + head->size) == rhead->addr) { head->next = rhead->next; head->size = head->size + rhead->size; MEM_Free(rhead); } } return retVal; }
/** * Loads the JVM. Every time this method is invoked, it attempts to create * a new JavaVM context. */ JavaVM * JVM_Create(JVM * jvm, int argc, Str args[]) { static Str szCreateVM = "JNI_CreateJavaVM"; /* load the JVM library */ if (!jvm->hModule) { jvm->hModule = LoadLibrary(jvm->javaLib); if (jvm->hModule) { FARPROC proc = GetProcAddress(jvm->hModule,szCreateVM); if (proc) { jvm->createVM = (CreateJavaVM)proc; } else { Error("ERROR: %s not found in %s\n",szCreateVM,jvm->javaLib); FreeLibrary(jvm->hModule); jvm->hModule = NULL; } } } /* create new VM */ if (jvm->createVM) { JavaVMInitArgs vm_args; memset(&vm_args, 0, sizeof(vm_args)); vm_args.version = JNI_VERSION_1_2; vm_args.ignoreUnrecognized = JNI_TRUE; vm_args.nOptions = argc; if (argc) { vm_args.options = MEM_NewArray(JavaVMOption,argc); if (vm_args.options) { int i; for (i=0; i<vm_args.nOptions; i++) { JavaVMOption * option = vm_args.options + i; memset(option, 0, sizeof(*option)); option->optionString = (char*)args[i]; } } } if (!argc || vm_args.options) { __try { JNIEnv * env = NULL; JavaVM * vm = NULL; int status = jvm->createVM(&vm, (void**)&env, &vm_args); ASSERT(status >= 0); if (status >= 0) { MEM_Free(vm_args.options); return vm; } } __except(EXCEPTION_EXECUTE_HANDLER) { ASSMSG2("EXCEPTION %08lX in %s",GetExceptionCode(),szCreateVM); } MEM_Free(vm_args.options); }
STATIC void EXPAT_StartElement(void * ctx, XML_Str tag, XML_Str * atts) { ExpatContext * expat = (ExpatContext *)ctx; if (expat->cb.startElem) { XMLAttr aset; XML_Str * s = atts; BUFFER_Clear(&expat->buf); BUFFER_Clear(&expat->atts); while (*s) { wchar_t* ws; XML_Str xs = *s++; /* * store offset in the vector - later will be replaces with the * pointer. Cannot store the pointers now because buffer may be * reallocated during conversion. */ const int off = BUFFER_Size(&expat->buf)/sizeof(Char); BUFFER_Put(&expat->atts, &off, sizeof(off), False); /* Convert from UTF-8 XML_Str to Str */ ws = STRING_ToUnicode(xs); if (ws) { #ifdef UNICODE BUFFER_Put(&expat->buf,ws,(wcslen(ws)+1)*sizeof(ws[0]),False); #else char * mb = STRING_ToMultiByte(ws); if (mb) { BUFFER_Put(&expat->buf, mb, strlen(mb)+1, False); MEM_Free(mb); } else { BUFFER_Put(&expat->buf, xs, strlen(xs)+1, False); } #endif MEM_Free(ws); } } ASSERT(!((BUFFER_Size(&expat->atts)/sizeof(int))%2)); aset.storage = BUFFER_Access(&expat->buf); aset.size = BUFFER_Size(&expat->buf); aset.off = BUFFER_Access(&expat->atts); aset.n = BUFFER_Size(&expat->atts)/sizeof(int)/2; EXPAT_ConvertTag(&expat->sb, tag); (*expat->cb.startElem)(expat->ctx, STRBUF_Text(&expat->sb), &aset); } }
/*********************************************************************** * * Função: GRA Destruir vértice * * Descrição: * Função responsável por destruir vértices. Passada como ponteiro de funcao para listas de vértices. * ***********************************************************************/ void DestruirVertice(void *pVazio) { tpVertice *pVertice = (tpVertice*) pVazio; LIS_DestruirLista(pVertice->pAntecessores); LIS_DestruirLista(pVertice->pSucessores); pVertice->destruirValor(pVertice->pValor); MEM_Free(pVertice->nome); MEM_Free(pVertice); }
/* * ======== NODEWRAP_GetUUIDProps ======== */ u32 NODEWRAP_GetUUIDProps(union Trapped_Args *args, void *pr_ctxt) { DSP_STATUS status = DSP_SOK; struct DSP_UUID nodeId; struct DSP_NDBPROPS *pnodeProps = NULL; GT_0trace(WCD_debugMask, GT_ENTER, "NODEWRAP_GetUUIDPropste: entered\n"); cp_fm_usr(&nodeId, args->ARGS_NODE_GETUUIDPROPS.pNodeID, status, 1); if (DSP_FAILED(status)) goto func_cont; pnodeProps = MEM_Alloc(sizeof(struct DSP_NDBPROPS), MEM_NONPAGED); if (pnodeProps != NULL) { status = NODE_GetUUIDProps(args-> ARGS_NODE_GETUUIDPROPS.hProcessor, &nodeId, pnodeProps); cp_to_usr(args->ARGS_NODE_GETUUIDPROPS.pNodeProps, pnodeProps, status, 1); } else status = DSP_EMEMORY; func_cont: if (pnodeProps) MEM_Free(pnodeProps); return status; }
STATIC void DIR_ItrFree(Iterator * itr) { Win32DirIterator * w = CAST(itr,Win32DirIterator,common.itr); DIR_ItrDestroy(&w->common); FindClose(w->handle); MEM_Free(w); }
/* * ======== MGRWRAP_EnumNode_Info ======== */ u32 MGRWRAP_EnumNode_Info(union Trapped_Args *args, void *pr_ctxt) { u8 *pNDBProps; u32 uNumNodes; DSP_STATUS status = DSP_SOK; u32 size = args->ARGS_MGR_ENUMNODE_INFO.uNDBPropsSize; GT_4trace(WCD_debugMask, GT_ENTER, "MGR_EnumNodeInfo: entered args:\n0x%x" " uNode: 0x%x\tpNDBProps: 0x%x\tuNDBPropsSize: " "0x%x\tpuNumNodes\n", args->ARGS_MGR_ENUMNODE_INFO.uNode, args->ARGS_MGR_ENUMNODE_INFO.pNDBProps, args->ARGS_MGR_ENUMNODE_INFO.uNDBPropsSize, args->ARGS_MGR_ENUMNODE_INFO.puNumNodes); pNDBProps = MEM_Alloc(size, MEM_NONPAGED); if (pNDBProps == NULL) status = DSP_EMEMORY; if (DSP_SUCCEEDED(status)) { status = MGR_EnumNodeInfo(args->ARGS_MGR_ENUMNODE_INFO.uNode, (struct DSP_NDBPROPS *)pNDBProps, size, &uNumNodes); } cp_to_usr(args->ARGS_MGR_ENUMNODE_INFO.pNDBProps, pNDBProps, status, size); cp_to_usr(args->ARGS_MGR_ENUMNODE_INFO.puNumNodes, &uNumNodes, status, 1); if (pNDBProps) MEM_Free(pNDBProps); return status; }
/* * ======== STRMWRAP_FreeBuffer ======== */ u32 STRMWRAP_FreeBuffer(union Trapped_Args *args, void *pr_ctxt) { DSP_STATUS status = DSP_SOK; u8 **apBuffer = NULL; u32 uNumBufs = args->ARGS_STRM_FREEBUFFER.uNumBufs; DBC_Require(uNumBufs <= MAX_BUFS); apBuffer = MEM_Alloc((uNumBufs * sizeof(u8 *)), MEM_NONPAGED); cp_fm_usr(apBuffer, args->ARGS_STRM_FREEBUFFER.apBuffer, status, uNumBufs); if (DSP_SUCCEEDED(status)) { mutex_lock(&((struct PROCESS_CONTEXT *)pr_ctxt)->strm_lock); status = STRM_FreeBuffer(args->ARGS_STRM_FREEBUFFER.hStream, apBuffer, uNumBufs, pr_ctxt); mutex_unlock(&((struct PROCESS_CONTEXT *)pr_ctxt)->strm_lock); } cp_to_usr(args->ARGS_STRM_FREEBUFFER.apBuffer, apBuffer, status, uNumBufs); if (apBuffer) MEM_Free(apBuffer); return status; }
/* * ======== MGRWRAP_EnumProc_Info ======== */ u32 MGRWRAP_EnumProc_Info(union Trapped_Args *args, void *pr_ctxt) { u8 *pProcessorInfo; u32 uNumProcs; DSP_STATUS status = DSP_SOK; u32 size = args->ARGS_MGR_ENUMPROC_INFO.uProcessorInfoSize; GT_4trace(WCD_debugMask, GT_ENTER, "MGRWRAP_EnumProc_Info: entered args:\n" "0x%x uProcessor: 0x%x\tpProcessorInfo: 0x%x\t" "uProcessorInfoSize: 0x%x\tpuNumProcs \n", args->ARGS_MGR_ENUMPROC_INFO.uProcessor, args->ARGS_MGR_ENUMPROC_INFO.pProcessorInfo, args->ARGS_MGR_ENUMPROC_INFO.uProcessorInfoSize, args->ARGS_MGR_ENUMPROC_INFO.puNumProcs); pProcessorInfo = MEM_Alloc(size, MEM_NONPAGED); if (pProcessorInfo == NULL) status = DSP_EMEMORY; if (DSP_SUCCEEDED(status)) { status = MGR_EnumProcessorInfo(args-> ARGS_MGR_ENUMPROC_INFO.uProcessor, (struct DSP_PROCESSORINFO *)pProcessorInfo, size, &uNumProcs); } cp_to_usr(args->ARGS_MGR_ENUMPROC_INFO.pProcessorInfo, pProcessorInfo, status, size); cp_to_usr(args->ARGS_MGR_ENUMPROC_INFO.puNumProcs, &uNumProcs, status, 1); if (pProcessorInfo) MEM_Free(pProcessorInfo); return status; }
/* * ======== DBLL_close ======== */ void DBLL_close(struct DBLL_LibraryObj *zlLib) { struct DBLL_TarObj *zlTarget; DBC_Require(cRefs > 0); DBC_Require(MEM_IsValidHandle(zlLib, DBLL_LIBSIGNATURE)); DBC_Require(zlLib->openRef > 0); zlTarget = zlLib->pTarget; GT_1trace(DBLL_debugMask, GT_ENTER, "DBLL_close: lib: 0x%x\n", zlLib); zlLib->openRef--; if (zlLib->openRef == 0) { /* Remove library from list */ if (zlTarget->head == zlLib) zlTarget->head = zlLib->next; if (zlLib->prev) (zlLib->prev)->next = zlLib->next; if (zlLib->next) (zlLib->next)->prev = zlLib->prev; /* Free DOF resources */ dofClose(zlLib); if (zlLib->fileName) MEM_Free(zlLib->fileName); /* remove symbols from symbol table */ if (zlLib->symTab) GH_delete(zlLib->symTab); /* remove the library object itself */ MEM_FreeObject(zlLib); zlLib = NULL; } }
/* * ======== WMD_CHNL_Destroy ======== * Purpose: * Close all open channels, and destroy the channel manager. */ DSP_STATUS WMD_CHNL_Destroy(struct CHNL_MGR *hChnlMgr) { DSP_STATUS status = DSP_SOK; struct CHNL_MGR *pChnlMgr = hChnlMgr; u32 iChnl; if (MEM_IsValidHandle(hChnlMgr, CHNL_MGRSIGNATURE)) { /* Close all open channels: */ for (iChnl = 0; iChnl < pChnlMgr->cChannels; iChnl++) { if (DSP_SUCCEEDED (WMD_CHNL_Close(pChnlMgr->apChannel[iChnl]))) { DBC_Assert(pChnlMgr->apChannel[iChnl] == NULL); } } /* release critical section */ if (pChnlMgr->hCSObj) SYNC_DeleteCS(pChnlMgr->hCSObj); /* Free channel manager object: */ if (pChnlMgr->apChannel) MEM_Free(pChnlMgr->apChannel); /* Set hChnlMgr to NULL in device object. */ DEV_SetChnlMgr(pChnlMgr->hDevObject, NULL); /* Free this Chnl Mgr object: */ MEM_FreeObject(hChnlMgr); } else { status = DSP_EHANDLE; } return status; }
/** * Deletes the BitSet */ void BITSET_Delete(BitSet * bs) { if (bs) { BITSET_Destroy(bs); MEM_Free(bs); } }
/****************************************************************************\ * * NT_QueryObjectName() * * DESCRIPTION: * * Queries the name of the object (such as a device or file object). * The caller must deallocate the return value with MEM_Free. The * returned string (if not NULL) is guaranteed to be NULL terminated. * * ARGUMENTS: * * obj - the object whose name to query * \****************************************************************************/ OBJECT_NAME_INFORMATION * NT_QueryObjectName(PVOID obj) { ULONG len = 0; NTSTATUS status = ObQueryNameString(obj, NULL, 0, &len); ASSERT(status != STATUS_SUCCESS); /* Unlike the rest of the system, ObQueryNameString returns * STATUS_INFO_LENGTH_MISMATCH instead of STATUS_BUFFER_TOO_SMALL * when passed too small a buffer. We expect to get this error here. * Anything else we can't handle. */ if (status == STATUS_INFO_LENGTH_MISMATCH && len > 0) { OBJECT_NAME_INFORMATION * name = MEM_Alloc(len + sizeof(WCHAR)); if (name) { /* NOTE: ObQueryNameString may return STATUS_SUCCESS and empty * string for unnamed objects */ status = ObQueryNameString(obj, name, len, &len); if (NT_SUCCESS(status) && name->Name.MaximumLength > 0) { /* make sure it's NULL terminated */ ULONG Last = name->Name.Length/sizeof(name->Name.Buffer[0]); name->Name.Buffer[Last] = 0; return name; } MEM_Free(name); } } return NULL; }
/** * Deletes and deallocates the event previously allocated with * EVENT_Create() */ void EVENT_Delete(Event * e) { if (e) { EVENT_Destroy(e); MEM_Free(e); } }
/** * Deletes and deallocates the mutex previously allocated with * RWLOCK_Create() */ void RWLOCK_Delete(RWLock * lock) { if (lock) { RWLOCK_Destroy(lock); MEM_Free(lock); } }
/* * ======== LST_Delete ======== * Purpose: * Removes a list by freeing its control structure's memory space. */ void LST_Delete(struct LST_LIST *pList) { GT_1trace(LST_debugMask, GT_ENTER, "LST_Delete: pList 0x%x\n", pList); if (pList) MEM_Free(pList); }
/** * Creates and starts n worker thread */ WorkQueue * WKQ_CreatePool(int n) { size_t size = sizeof(WorkQueue) + sizeof(ThrID)*(MAX(n,1)-1); WorkQueue * q = MEM_Alloc(size); if (q) { ASSERT(WKQ.initcount > 0); if (WKQ.initcount == 0) WKQ_InitModule(); memset(q, 0, size); q->nthreads = n; if (MUTEX_Init(&q->mutex)) { if (EVENT_Init(&q->event)) { if (EVENT_Init(&q->stopEvent)) { if (EVENT_Reset(&q->stopEvent)) { int i; q->flags = WKQ_ACTIVE; QUEUE_Init(&q->items); QUEUE_Init(&q->submit); for (i=0; i<n; i++) { if (!THREAD_Create(q->threads+i, WKQ_Thread, q)) { WKQ_Delete(q); return NULL; } } return q; } EVENT_Destroy(&q->stopEvent); } EVENT_Destroy(&q->event); } MUTEX_Destroy(&q->mutex); } MEM_Free(q); } return NULL; }
/** * Deletes the critical section */ void CS_Delete(CritSect * cs) { if (cs) { CS_Destroy(cs); MEM_Free(cs); } }
/** * Returns a wait context from the pool, or allocates a new one */ STATIC Waiter * WKQ_GetWaiter(WorkQueueModule * module) { Waiter * waiter = NULL; ASSERT(module->initcount > 0); if (module->waitpool) { MUTEX_Lock(&module->mutex); if (module->waitpool) { waiter = module->waitpool; module->waitpool = waiter->next; waiter->next = NULL; module->nwait--; ASSERT(module->nwait >= 0); ASSERT(module->nwait || !module->waitpool); } MUTEX_Unlock(&module->mutex); } if (!waiter) { waiter = MEM_New(Waiter); if (waiter) { if (!EVENT_Init(&waiter->event)) { MEM_Free(waiter); waiter = NULL; } } } if (waiter) { EVENT_Reset(&waiter->event); } return waiter; }
/** * This function resolves host name or dotted IP representation into 32 bit * binary IP address in host byte order. This function mostly deals with the * stupidity of Windoze implementation of gethostbyname() which, given an * IP address in standard dot notation, is unable to convert it into a * binary form. */ Bool INET_ResolveAddr(Str s, IPaddr * addr) { Bool ok = False; if (s) { while (*s && IsSpace(*s)) s++; if (*s) { #ifdef UNICODE char * host = STRING_ToMultiByte(s); if (host) { #else /* UNICODE */ const char * host = s; #endif /* UNICODE */ IPaddr tmp = inet_addr(host); if (tmp == INADDR_NONE) { struct hostent * h = gethostbyname(host); if (h && h->h_addr_list[0]) { tmp = *((IPaddr*)h->h_addr_list[0]); ok = True; } } else { ok = True; } if (ok && addr) *addr = ntohl(tmp); #ifdef UNICODE MEM_Free(host); } #endif /* UNICODE */ } } return ok; }
/** * Deletes random number generator context. */ void RANDOM_Delete(Random * r) { if (r) { RANDOM_Destroy(r); MEM_Free(r); } }
STATIC void ZipFree(File * f) { Zip * zf = ZipCast(f); if (zf) { ASSERT(!(f->flags & FILE_IS_OPEN)); MEM_Free(zf); } }
/** * Destroys the BitSet */ void BITSET_Destroy(BitSet * bs) { if (bs->alloc) { ASSERT(bs->storage.units); MEM_Free(bs->storage.units); } memset(bs, 0, sizeof(*bs)); }
STATIC void SocketFree(File * f) { SocketFile * s = SocketFileCast(f); if (s) { ASSERT(!(f->flags & FILE_IS_OPEN)); MEM_Free(s); } }
/* * ======== FreeChirpList ======== * Purpose: * Free the queue of Chirps. */ static void FreeChirpList(struct LST_LIST *pChirpList) { DBC_Require(pChirpList != NULL); while (!LST_IsEmpty(pChirpList)) MEM_Free(LST_GetHead(pChirpList)); LST_Delete(pChirpList); }
/** * "connect" method handler */ STATIC XRpcElement* GWENG_MidpConnect(void* ctx, const XRpcContainer* param) { /* decode parameters */ const XRpcIntElement* sidParam = XRPC_GetIntElementByName(param, ECMTGW_SEI_CONNECT_SID_PARAM); const XRpcIntElement* cidParam = XRPC_GetIntElementByName(param, ECMTGW_SEI_CONNECT_CID_PARAM); const XRpcShortElement* portParam = XRPC_GetShortElementByName(param, ECMTGW_SEI_CONNECT_PORT_PARAM); if (sidParam && cidParam && portParam) { MidpSession* midp; EcmtGateway* gw = ctx; I32u cid = XRPC_GetInt(cidParam); Port port = XRPC_GetShort(portParam); MidpSessionKey key; key.xrpcSid = XRPC_GetInt(sidParam); key.xrpcSession = XRPC_GetCurrentSession(gw->xrpc); TRACE4("GW: MidpConnect(%08x.%08x.%u, port %hu)\n", key.xrpcSession, key.xrpcSid, cid, port); MUTEX_Lock(&gw->mutex); midp = HASH_Get(&gw->midpSessionMap,&key); if (midp) { MidpConnection* conn = MEM_New(MidpConnection); if (conn) { memset(conn, 0, sizeof(*conn)); conn->connId = cid; if (HASH_Put(&midp->connMap, (HashKey)cid, conn)) { char pkt[ECMT_MIDP_DEBUG_CONNECT_SIZE]; GWENG_MidpFillHeader(pkt,midp->sid,ECMT_MIDP_DEBUG_OPCODE_CONNECT); *((I32u*)(pkt+ECMT_MIDP_DEBUG_CONNECT_CID_OFFSET)) = htonl(cid); *((I16u*)(pkt+ECMT_MIDP_DEBUG_CONNECT_PORT_OFFSET)) = htons(port); GWENG_QueueAdd(gw->handsetQueue, KECMT_MIDP_DEBUG_PLUGIN_UID, pkt, ECMT_MIDP_DEBUG_CONNECT_SIZE); MUTEX_Unlock(&gw->mutex); return NULL; } MEM_Free(conn); } GWENG_MidpResetConn(gw, midp, cid, False, True); } else { TRACE3("GW: unexpected MIDP connect (%08x.%08x.%u)\n", key.xrpcSession, key.xrpcSid, cid); } MUTEX_Unlock(&gw->mutex); } return NULL; }