void freeMetric(Metric *m) { int numinst; /* Metric is on fetch list */ if (m->profile) { if (m->prev) { m->prev->next = m->next; if (m->next) m->next->prev = m->prev; } else { m->host->waits = m->next; if (m->next) m->next->prev = NULL; } if (m->host) freeHost(m->host); } symFree(m->hname); numinst = m->specinst == 0 ? m->m_idom : m->specinst; if (numinst > 0 && m->inames) { int i; for (i = 0; i < numinst; i++) { if (m->inames[i] != NULL) free(m->inames[i]); } free(m->inames); } if (numinst && m->iids) free(m->iids); if (m->vals) free(m->vals); }
TEST(Memory, recover) { cleanSlate(); // Clean up everything done so far try { array vec[100]; // Trying to allocate 1 Terrabyte of memory and trash the memory manager // should crash memory manager for (int i = 0; i < 1000; i++) { vec[i] = randu(1024, 1024, 256); // Allocating 1GB } ASSERT_EQ(true, false); // Is there a simple assert statement? } catch (exception &ae) { ASSERT_EQ(ae.err(), AF_ERR_NO_MEM); const int num = 1000 * 1000; const float val = 1.0; array a = constant(val, num); // This should work as expected float *h_a = a.host<float>(); for (int i = 0; i < 1000 * 1000; i++) { ASSERT_EQ(h_a[i], val); } freeHost(h_a); } }
JRawData::~JRawData() { if (m_data_ptr && m_own_data) { freeHost(m_data_ptr); } }
void JRawData::SetData(void* data) { if (m_own_data) { freeHost(m_data_ptr); } m_data_ptr = data; m_own_data = false; }
Host* initHost(const char* src, const int dataSize){ // allocate new host Host* h = (Host*)malloc(sizeof(Host)); if(!h){ error("initHost()", "failed to allocate memory for host"); return NULL; } h->data=NULL; h->dLen=0; h->ptr=NULL; h->instr=NULL; h->param=NULL; h->iLen=0; // parse source code if(!parse(h, src)){ error("initHost()", "failed to parse source code"); freeHost(h); return NULL; } // allocate memory for data tape h->data = (char*)calloc(dataSize,sizeof(char)); if(!h->data){ error("initHost()", "failed to initalize data tape"); freeHost(h); return NULL; } h->ptr=h->data; h->dLen = dataSize; // STDIO thingies h->esc=0; h->out=NULL; h->in=NULL; // API thingies void* defStates = getDefStates(); memcpy(h->apiStates, defStates, sizeof(void*)*256); free(defStates); // w00t return h; }
/* * General method for tests that erode an input image with a morphMask and write the result to filenameOut if != NULL */ void testErosion(cudaPaddedImage input, cudaImage output, rect2d roi, morphMask mask, const char* filenameOut, const char* textOnError) { performErosion(getData(input), getPitch(input), getData(output), getPitch(output), roi, mask, input.border); if (filenameOut != NULL) { float *host_out = copyImageToHost(output); printf("output width: %d , height: %d\n", output.width, output.height); savePGM(filenameOut, host_out, output.width, output.height); freeHost(host_out, PINNED); } exitOnError(textOnError); }
void freeFetch(Fetch *f) { if (f->profiles == NULL) { if (f->next) f->next->prev = f->prev; if (f->prev) f->prev->next = f->next; else { f->host->fetches = f->next; freeHost(f->host); } pmDestroyContext(f->handle); if (f->result) pmFreeResult(f->result); if (f->pmids) free(f->pmids); free(f); } }
int main(void) { char const * const listFile = "rsshHosts.conf"; list_t *hosts = list_create(); readHostList(listFile, hosts); list_t *hptr = hosts; while (hptr) { host_t *h = (host_t *)(hptr->item); if (h) printf("%s port %d\n", h->name, h->port); hptr = list_nextItem(hptr); } hptr = hosts; while (hptr) { freeHost(hptr->item); hptr = hptr->next; } list_free(hosts); return 0; }