static void RemoteTransformer_Destroy(Transformer_t* transformer) { RemoteTransformer_t *remoteTransformer = (RemoteTransformer_t *) transformer; EMBX_ERROR err; remoteTransformer->super.info->referenceCount--; /* clean up the buffer cache (allocated during execution) */ while (remoteTransformer->bufferCache) { void *buf = allocBuffer(remoteTransformer, 1); if (buf) { EMBX_ERROR err; err = EMBX_Free(buf); MME_Assert(EMBX_SUCCESS == err); } } if (remoteTransformer->adminPort) { err = EMBX_ClosePort(remoteTransformer->adminPort); MME_Assert(EMBX_SUCCESS == err); /* no recovery possible */ } EMBX_OS_EVENT_DESTROY(&remoteTransformer->terminateWasReplied); EMBX_OS_MUTEX_DESTROY(&remoteTransformer->commandSlotLock); EMBX_OS_MemFree(remoteTransformer->commandSlots); EMBX_OS_MemFree(remoteTransformer); }
MME_ERROR MME_FreeDataBuffer(MME_DataBuffer_t *dataBuffer) { struct InternalDataBuffer *buf = (struct InternalDataBuffer *) dataBuffer; #ifndef MME_LEAN_AND_MEAN if (manager == NULL) { return MME_DRIVER_NOT_INITIALIZED; /* the manager must exist */ } if (NULL == buf) { return MME_INVALID_ARGUMENT; } if (buf->buffer.ScatterPages_p != buf->pages) { return MME_INVALID_ARGUMENT; } #endif if (0 == (buf->flags & MME_ALLOCATION_CACHED)) { if (EMBX_SUCCESS != EMBX_Free(buf->pages[0].Page_p)) { return MME_INVALID_ARGUMENT; } } EMBX_OS_MemFree(buf); return MME_SUCCESS; }
static void cleanupTerminateMMEMessage(TransportInfo_t *tpInfo, TransformerTerminateMMEMessage* buffer) { EMBX_ERROR err; err = EMBX_Free(buffer); MME_Assert(EMBX_SUCCESS == err); }
static void cleanupRegisteredMessage(TransportInfo_t *tpInfo, TransformerRegisteredMessage *msg) { EMBX_ERROR err; err = EMBX_Free(msg); MME_Assert(EMBX_SUCCESS == err); }
/* The list management here is extremely vulnerable to duplicate frees. this * will make the buffer list cyclic resulting either in the buffer release * code in RemoteTransformer_Term() looping forever or (worse) memory * being allocated twice. */ static void freeBuffer(RemoteTransformer_t *remoteTransformer, EMBX_VOID *ptr) { EMBX_UINT sz; EMBX_ERROR err; err = EMBX_GetBufferSize(ptr, &sz); MME_Assert(EMBX_SUCCESS == err); if (sz == 4096) { EMBX_VOID **p = ptr; MME_Assert(ptr != remoteTransformer->bufferCache); EMBX_OS_INTERRUPT_LOCK(); *p = remoteTransformer->bufferCache; remoteTransformer->bufferCache = p; EMBX_OS_INTERRUPT_UNLOCK(); } else { EMBX_ERROR err = EMBX_Free(ptr); MME_Assert(EMBX_SUCCESS == err); } }
int run_test(void) { EMBX_UINT i; EMBX_ERROR res; EMBX_TPINFO tpinfo1; EMBX_BOOL bFailed; EMBX_PORT localPort,remotePort; EMBX_VOID *buffer1; EMBX_FACTORY factory; EMBX_RECEIVE_EVENT ev; bFailed = EMBX_FALSE; buffer1 = 0; /* Test 1 */ res = EMBX_ReceiveBlock(EMBX_INVALID_HANDLE_VALUE, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test1 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } res = EMBX_RegisterTransport(EMBXLB_loopback_factory, &loopback_config, sizeof(EMBXLB_Config_t), &factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Transport Registration failed, res = %s, exiting\n",error_strings[res])); goto skip_remaining_tests; } /* Test 2 */ res = EMBX_Init(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test2 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 3 */ res = EMBX_GetFirstTransport(&tpinfo1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test3 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 4 */ res = EMBX_OpenTransport(tpinfo1.name, &tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test4 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 5 */ res = EMBX_CreatePort(tp, "testport", &localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test5 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 6 */ res = EMBX_Connect(tp, "testport", &remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test6 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 7 */ res = EMBX_ReceiveBlock(tp, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test7 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 8 */ res = EMBX_ReceiveBlock(remotePort, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test8 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 9 */ res = EMBX_ReceiveBlock(localPort, 0); if(res != EMBX_INVALID_ARGUMENT) { EMBX_Info(EMBX_TRUE, ("Test9 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 10 */ res = EMBX_Alloc(tp, BUFFER_SIZE, &buffer1); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test10 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } for(i=0;i<BUFFER_SIZE;i++) { ((unsigned char *)buffer1)[i] = (unsigned char)i; } /* Test 11 */ res = EMBX_SendMessage(remotePort, buffer1, BUFFER_SIZE); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test11 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 12 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test12 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != EMBX_INVALID_HANDLE_VALUE || ev.offset != 0 || ev.type != EMBX_REC_MESSAGE || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test13 failed, event structure incorrect\n")); goto skip_remaining_tests; } for(i=0;i<ev.size;i++) { if( ((unsigned char *)ev.data)[i] != (unsigned char)i ) { EMBX_Info(EMBX_TRUE, ("Test13 failed, buffer contents incorrect\n")); bFailed = EMBX_TRUE; break; } } /* Test 13 */ res = EMBX_Free(ev.data); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test13 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(!EMBX_OS_ThreadCreate(send_thread, (void *)remotePort, EMBX_DEFAULT_THREAD_PRIORITY, "send")) { EMBX_Info(EMBX_TRUE, ("Unable to create thread\n")); goto skip_remaining_tests; } /* Test 14 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test14 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } if(ev.handle != EMBX_INVALID_HANDLE_VALUE || ev.offset != 0 || ev.type != EMBX_REC_MESSAGE || ev.size != BUFFER_SIZE) { EMBX_Info(EMBX_TRUE, ("Test15 failed, event structure incorrect\n")); goto skip_remaining_tests; } /* Test 15 */ res = EMBX_Free(ev.data); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test15 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 16 */ res = EMBX_ClosePort(remotePort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test16 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 17 */ res = EMBX_ClosePort(localPort); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test17 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 18 */ res = EMBX_CloseTransport(tp); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test18 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* Test 19 */ res = EMBX_Deinit(); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test19 failed, res = %s\n",error_strings[res])); goto skip_remaining_tests; } /* These test a different code path to the identical tests done before * EMBX_Init */ /* Test 20 */ res = EMBX_ReceiveBlock(localPort, &ev); if(res != EMBX_INVALID_PORT) { EMBX_Info(EMBX_TRUE, ("Test20 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } /* Test 21 */ res = EMBX_UnregisterTransport(factory); if(res != EMBX_SUCCESS) { EMBX_Info(EMBX_TRUE, ("Test21 failed, res = %s\n",error_strings[res])); bFailed = EMBX_TRUE; } return bFailed?-1:0; skip_remaining_tests: EMBX_Info(EMBX_TRUE, ("Skipping Remaining Tests\n")); return -1; }