oscar_tlv* oscar_tlv_chain::putTLV(WORD wType, WORD wLen, BYTE *pData, BOOL bReplace) { oscar_tlv *tlv = getTLV(wType, 1); if (tlv && bReplace) SAFE_FREE((void**)&tlv->pData); else { oscar_tlv_chain *last = this; while (last && last->next) last = last->next; if (last) { last->next = (oscar_tlv_chain*)SAFE_MALLOC(sizeof(oscar_tlv_chain)); tlv = &last->next->tlv; tlv->wType = wType; } } if (tlv) { tlv->wLen = wLen; tlv->pData = (PBYTE)SAFE_MALLOC(wLen); memcpy(tlv->pData, pData, wLen); } return tlv; }
void * btreeCreateNodeBlock(GdbBlock *block, void *extra) { BTreeNode *node; BTree *tree; tree = (BTree *)extra; MEM_CHECK(node = (BTreeNode *)SAFE_MALLOC(sizeof(BTreeNode), LOC_BTREE_0166)); memset(node, 0, sizeof(BTreeNode)); node->tree = tree; node->block = block; /*comment: when reach here, we have no idea about keyCount, hence alloc children/keySizes/keys as the max possible num: the order*/ MEM_CHECK(node->children = (offset_t *)SAFE_MALLOC(tree->order * sizeof(offset_t), LOC_BTREE_0167)); memset(node->children, 0, tree->order * sizeof(offset_t)); MEM_CHECK(node->keySizes = (uint16_t *)SAFE_MALLOC((tree->order - 1) * sizeof(uint16_t), LOC_BTREE_0168)); memset(node->keySizes, 0, (tree->order - 1) * sizeof(uint16_t)); MEM_CHECK(node->keys = (uint8_t **)SAFE_MALLOC((tree->order - 1) * sizeof(uint8_t *), LOC_BTREE_0169)); memset(node->keys, 0, (tree->order - 1) * sizeof(uint8_t *)); return node; }
static void child_alloc(int *bufsz_arr) { char **foo; int i, j; char buf[BUFSIZ]; long count; foo = SAFE_MALLOC(tst_exit, nr_iovecs * sizeof(char *)); count = 0; for (i = 0; i < nr_iovecs; i++) { foo[i] = SAFE_MALLOC(tst_exit, bufsz_arr[i]); for (j = 0; j < bufsz_arr[i]; j++) { foo[i][j] = count % 256; count++; } } tst_resm(TINFO, "child 0: %d iovecs allocated and initialized.", nr_iovecs); /* passing addr via pipe */ SAFE_CLOSE(tst_exit, pipe_fd[0]); snprintf(buf, BUFSIZ, "%p", (void *)foo); SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf)); SAFE_CLOSE(tst_exit, pipe_fd[1]); /* wait until child_invoke is done reading from our VM */ safe_semop(semid, 0, -1); }
static void setup(void) { int node, ret; tst_require_root(); TEST(ltp_syscall(__NR_migrate_pages, 0, 0, NULL, NULL)); if (numa_available() == -1) tst_brkm(TCONF, NULL, "NUMA not available"); ret = get_allowed_nodes(NH_MEMS, 1, &node); if (ret < 0) tst_brkm(TBROK | TERRNO, NULL, "get_allowed_nodes_arr: %d", ret); sane_max_node = LTP_ALIGN(get_max_node(), sizeof(unsigned long)*8); sane_nodemask_size = sane_max_node / 8; sane_old_nodes = SAFE_MALLOC(NULL, sane_nodemask_size); sane_new_nodes = SAFE_MALLOC(NULL, sane_nodemask_size); memset(sane_old_nodes, 0, sane_nodemask_size); memset(sane_new_nodes, 0, sane_nodemask_size); set_bit(sane_old_nodes, node, 1); set_bit(sane_new_nodes, node, 1); TEST_PAUSE; }
fenc_attribute_policy *construct_test_policy1() { fenc_attribute_policy *policy; fenc_attribute_subtree *subtree_AND, *subtree_L1, *subtree_L2, *subtree_L3, *subtree_L4, *subtree_L5, *subtree_OR; policy = (fenc_attribute_policy*)SAFE_MALLOC(sizeof(fenc_attribute_policy)); memset(policy, 0, sizeof(fenc_attribute_policy)); /* Add a simple one-level 3-out-of-3 policy. Eventually we'll have helper routines to * do this work. */ subtree_AND = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); subtree_L1 = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); subtree_L2 = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); subtree_L3 = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); subtree_L4 = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); subtree_L5 = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); subtree_OR = (fenc_attribute_subtree*)SAFE_MALLOC(sizeof(fenc_attribute_subtree)); memset(subtree_AND, 0, sizeof(fenc_attribute_subtree)); memset(subtree_L1, 0, sizeof(fenc_attribute_subtree)); memset(subtree_L2, 0, sizeof(fenc_attribute_subtree)); memset(subtree_L3, 0, sizeof(fenc_attribute_subtree)); memset(subtree_L4, 0, sizeof(fenc_attribute_subtree)); memset(subtree_L5, 0, sizeof(fenc_attribute_subtree)); memset(subtree_OR, 0, sizeof(fenc_attribute_subtree)); subtree_L1->node_type = FENC_ATTRIBUTE_POLICY_NODE_LEAF; strcpy((char*)subtree_L1->attribute.attribute_str, "ONE"); subtree_L2->node_type = FENC_ATTRIBUTE_POLICY_NODE_LEAF; strcpy((char*)subtree_L2->attribute.attribute_str, "TWO"); subtree_L3->node_type = FENC_ATTRIBUTE_POLICY_NODE_LEAF; strcpy((char*)subtree_L3->attribute.attribute_str, "THREE"); subtree_L4->node_type = FENC_ATTRIBUTE_POLICY_NODE_LEAF; strcpy((char*)subtree_L4->attribute.attribute_str, "FOUR"); subtree_L5->node_type = FENC_ATTRIBUTE_POLICY_NODE_LEAF; strcpy((char*)subtree_L5->attribute.attribute_str, "FIVE"); subtree_AND->node_type = FENC_ATTRIBUTE_POLICY_NODE_OR; subtree_AND->threshold_k = 2; subtree_AND->num_subnodes = 3; subtree_AND->subnode = SAFE_MALLOC(sizeof(fenc_attribute_subtree*) * 5); subtree_AND->subnode[0] = subtree_L1; subtree_AND->subnode[1] = subtree_L2; subtree_AND->subnode[2] = subtree_OR; subtree_OR->node_type = FENC_ATTRIBUTE_POLICY_NODE_AND; subtree_OR->subnode = SAFE_MALLOC(sizeof(fenc_attribute_subtree*) * 3); subtree_OR->num_subnodes = 3; subtree_OR->subnode[0] = subtree_L3; subtree_OR->subnode[1] = subtree_L4; subtree_OR->subnode[2] = subtree_L5; policy->root = subtree_AND; return policy; }
static void child_invoke(int *bufsz_arr) { int i, j, count, nr_error; unsigned char expect, actual; long *addrs; struct iovec local[NUM_LOCAL_VECS], *remote; int rcv_arr[NUM_LOCAL_VECS]; addrs = fetch_remote_addrs(); remote = SAFE_MALLOC(tst_exit, nr_iovecs * sizeof(struct iovec)); for (i = 0; i < nr_iovecs; i++) { remote[i].iov_base = (void *)addrs[i]; remote[i].iov_len = bufsz_arr[i]; } tst_resm(TINFO, "child 1: %d remote iovecs received.", nr_iovecs); gen_random_arr(rcv_arr, NUM_LOCAL_VECS); for (i = 0; i < NUM_LOCAL_VECS; i++) { local[i].iov_base = SAFE_MALLOC(tst_exit, rcv_arr[i]); local[i].iov_len = rcv_arr[i]; } tst_resm(TINFO, "child 1: %d local iovecs initialized.", NUM_LOCAL_VECS); TEST(test_process_vm_readv(pids[0], local, NUM_LOCAL_VECS, remote, nr_iovecs, 0)); if (TEST_RETURN != bufsz) tst_brkm(TBROK | TERRNO, tst_exit, "process_vm_readv"); /* verify every byte */ count = 0; nr_error = 0; for (i = 0; i < NUM_LOCAL_VECS; i++) { for (j = 0; j < local[i].iov_len; j++) { expect = count % 256; actual = ((unsigned char *)local[i].iov_base)[j]; if (expect != actual) { #if DEBUG tst_resm(TFAIL, "child 1: expected %i, got %i " "for byte seq %d", expect, actual, count); #endif nr_error++; } count++; } } if (nr_error) tst_brkm(TFAIL, tst_exit, "child 1: %d incorrect bytes " "received.", nr_error); else tst_resm(TPASS, "child 1: all bytes are correctly received."); }
M4OSA_ERR VideoEditorMp3Reader_getInterface( M4READER_MediaType *pMediaType, M4READER_GlobalInterface **pRdrGlobalInterface, M4READER_DataInterface **pRdrDataInterface) { M4OSA_ERR err = M4NO_ERROR; ALOGV("VideoEditorMp3Reader_getInterface: begin"); /* Input parameters check */ VIDEOEDITOR_CHECK(M4OSA_NULL != pMediaType, M4ERR_PARAMETER); VIDEOEDITOR_CHECK(M4OSA_NULL != pRdrGlobalInterface, M4ERR_PARAMETER); VIDEOEDITOR_CHECK(M4OSA_NULL != pRdrDataInterface, M4ERR_PARAMETER); SAFE_MALLOC(*pRdrGlobalInterface, M4READER_GlobalInterface, 1, "VideoEditorMp3Reader_getInterface"); SAFE_MALLOC(*pRdrDataInterface, M4READER_DataInterface, 1, "VideoEditorMp3Reader_getInterface"); *pMediaType = M4READER_kMediaTypeMP3; (*pRdrGlobalInterface)->m_pFctCreate = VideoEditorMp3Reader_create; (*pRdrGlobalInterface)->m_pFctDestroy = VideoEditorMp3Reader_destroy; (*pRdrGlobalInterface)->m_pFctOpen = VideoEditorMp3Reader_open; (*pRdrGlobalInterface)->m_pFctClose = VideoEditorMp3Reader_close; (*pRdrGlobalInterface)->m_pFctGetOption = VideoEditorMp3Reader_getOption; (*pRdrGlobalInterface)->m_pFctSetOption = VideoEditorMp3Reader_setOption; (*pRdrGlobalInterface)->m_pFctGetNextStream = VideoEditorMp3Reader_getNextStream; (*pRdrGlobalInterface)->m_pFctFillAuStruct = VideoEditorMp3Reader_fillAuStruct; (*pRdrGlobalInterface)->m_pFctStart = M4OSA_NULL; (*pRdrGlobalInterface)->m_pFctStop = M4OSA_NULL; (*pRdrGlobalInterface)->m_pFctJump = VideoEditorMp3Reader_jump; (*pRdrGlobalInterface)->m_pFctReset = VideoEditorMp3Reader_reset; (*pRdrGlobalInterface)->m_pFctGetPrevRapTime = M4OSA_NULL; (*pRdrDataInterface)->m_pFctGetNextAu = VideoEditorMp3Reader_getNextAu; (*pRdrDataInterface)->m_readerContext = M4OSA_NULL; cleanUp: if( M4NO_ERROR == err ) { ALOGV("VideoEditorMp3Reader_getInterface no error"); } else { SAFE_FREE(*pRdrGlobalInterface); SAFE_FREE(*pRdrDataInterface); ALOGV("VideoEditorMp3Reader_getInterface ERROR 0x%X", err); } ALOGV("VideoEditorMp3Reader_getInterface: end"); return err; }
/* set maxTlvs<=0 to get all TLVs in length, or a positive integer to get at most the first n */ oscar_tlv_chain* readIntoTLVChain(BYTE **buf, WORD wLen, int maxTlvs) { oscar_tlv_chain *now, *last, *chain = NULL; WORD now_tlv_len; int len = wLen; if (!buf || !wLen) return NULL; while (len > 0) { /* don't use unsigned variable for this check */ now = (oscar_tlv_chain *)SAFE_MALLOC(sizeof(oscar_tlv_chain)); if (!now) { disposeChain(&chain); return NULL; } unpackWord(buf, &(now->tlv.wType)); unpackWord(buf, &now_tlv_len); now->tlv.wLen = now_tlv_len; len -= 4; if (now_tlv_len < 1) now->tlv.pData = NULL; else if (now_tlv_len <= len) { now->tlv.pData = (BYTE *)SAFE_MALLOC(now_tlv_len); if (now->tlv.pData) memcpy(now->tlv.pData, *buf, now_tlv_len); } else { // the packet is shorter than it should be SAFE_FREE((void**)&now); return chain; // give at least the rest of chain } if (chain) // keep the original order last->next = now; else chain = now; last = now; len -= now_tlv_len; *buf += now_tlv_len; if (--maxTlvs == 0) break; } return chain; }
static long *fetch_remote_addrs(void) { long *foo, *bar; char buf[BUFSIZ]; long len; struct iovec local, remote; /* get addr from pipe */ SAFE_CLOSE(tst_exit, pipe_fd[1]); SAFE_READ(tst_exit, 0, pipe_fd[0], buf, BUFSIZ); SAFE_CLOSE(tst_exit, pipe_fd[0]); if (sscanf(buf, "%p", &foo) != 1) tst_brkm(TBROK | TERRNO, tst_exit, "sscanf"); len = nr_iovecs * sizeof(long); bar = SAFE_MALLOC(tst_exit, len); local.iov_base = bar; local.iov_len = len; remote.iov_base = foo; remote.iov_len = len; TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0)); if (TEST_RETURN != len) tst_brkm(TFAIL | TERRNO, tst_exit, "process_vm_readv"); return local.iov_base; }
oscar_tlv_record_list* readIntoTLVRecordList(BYTE **buf, WORD wLen, int nCount) { oscar_tlv_record_list *list = NULL, *last; while (wLen >= 2) { WORD wRecordSize; unpackWord(buf, &wRecordSize); wLen -= 2; if (wRecordSize && wRecordSize <= wLen) { oscar_tlv_record_list *pRecord = (oscar_tlv_record_list*)SAFE_MALLOC(sizeof(oscar_tlv_record_list)); BYTE *pData = *buf; *buf += wRecordSize; wLen -= wRecordSize; pRecord->item = readIntoTLVChain(&pData, wRecordSize, 0); if (pRecord->item) { // keep the order if (list) last->next = pRecord; else list = pRecord; last = pRecord; } else SAFE_FREE((void**)&pRecord); } if (--nCount == 0) break; } return list; }
static void setup(void) { int i, fd; fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0664); pagesize = getpagesize(); /* Writing 16 pages of random data into this file */ for (i = 0; i < (pagesize / 2); i++) SAFE_WRITE(1, fd, STR, sizeof(STR) - 1); SAFE_FSTAT(fd, &st); file1 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); file2 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); file3 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); shared_anon = SAFE_MMAP(0, MAP_SIZE, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0); nonalign = file1 + 100; ptr_addr = SAFE_MALLOC(st.st_size); tmp_addr = (void*)LTP_ALIGN((long)ptr_addr, pagesize); /* unmap as last step to avoid subsequent mmap(s) pick same address */ SAFE_MUNMAP(file2 + st.st_size - pagesize, pagesize); SAFE_CLOSE(fd); tcases_filter(); }
static void setup(void) { struct rlimit rl = { .rlim_cur = RLIM_INFINITY, .rlim_max = RLIM_INFINITY, }; int i; long arg_len, arg_count; bst = SAFE_MMAP(NULL, sizeof(*bst), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); bst->left = 0; bst->right = ARGS_SZ; arg_len = sysconf(_SC_PAGESIZE); arg = SAFE_MALLOC(arg_len); memset(arg, 'c', arg_len - 1); arg[arg_len - 1] = '\0'; args[0] = "true"; arg_count = ARGS_SZ; tst_res(TINFO, "Using %ld args of size %ld", arg_count, arg_len); for (i = 1; i < arg_count; i++) args[i] = arg; SAFE_SETRLIMIT(RLIMIT_STACK, &rl); }
static void setup(void) { struct sysinfo sstats; unsigned long long total_free; struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGRTMIN, &act, 0); parse_mtest_options(opt_chunksize, &chunksize, opt_maxbytes, &maxbytes, opt_maxpercent, &maxpercent); sysinfo(&sstats); total_free = sstats.freeram; max_pids = total_free * sstats.mem_unit / (unsigned long)ALLOC_THRESHOLD + 10; pid_list = SAFE_MALLOC(max_pids * sizeof(pid_t)); if (!alloc_maxbytes) { /* set alloc_maxbytes to the extra amount we want to allocate */ alloc_maxbytes = ((float)maxpercent / 100.00) * (sstats.mem_unit * total_free); tst_res(TINFO, "Filling up %d%% of free ram which is %llu kbytes", maxpercent, alloc_maxbytes / 1024); } }
EC_BOOL cextclnt_recv(CEXTCLNT *cextclnt, UINT8 **in_buff, UINT32 *in_buff_size) { UINT32 data_size; UINT8 *data_buff; if(EC_FALSE == csocket_recv_uint32(CEXTCLNT_SOCKFD(cextclnt), &data_size)) { dbg_log(SEC_0069_CEXTSRV, 0)(LOGSTDOUT, "error:cextclnt_recv: recv data size from client %s on sockfd %d failed\n", CEXTCLNT_IPADDR_STR(cextclnt), CEXTCLNT_SOCKFD(cextclnt)); return (EC_FALSE); } data_buff = (UINT8 *)SAFE_MALLOC(data_size, LOC_CEXTSRV_0001); if(NULL_PTR == data_buff) { dbg_log(SEC_0069_CEXTSRV, 0)(LOGSTDOUT, "error:cextclnt_recv: alloc %ld bytes failed\n", data_size); return (EC_FALSE); } if(EC_FALSE == csocket_recv(CEXTCLNT_SOCKFD(cextclnt), data_buff, data_size)) { dbg_log(SEC_0069_CEXTSRV, 0)(LOGSTDOUT, "error:cextclnt_recv: recv %ld bytes from client %s on sockfd %d failed\n", data_size, CEXTCLNT_IPADDR_STR(cextclnt), CEXTCLNT_SOCKFD(cextclnt)); SAFE_FREE(data_buff, LOC_CEXTSRV_0002); return (EC_FALSE); } (*in_buff) = data_buff; (*in_buff_size) = data_size; return (EC_TRUE); }
/** **************************************************************************** * @brief create an instance of the MP3 reader * @note allocates the context * * @param pContext: (OUT) pointer on a reader context * * @return M4NO_ERROR there is no error * @return M4ERR_ALLOC a memory allocation has failed * @return M4ERR_PARAMETER at least one parameter is not valid **************************************************************************** */ M4OSA_ERR VideoEditorMp3Reader_create(M4OSA_Context *pContext) { M4OSA_ERR err = M4NO_ERROR; VideoEditorMp3Reader_Context *pReaderContext = M4OSA_NULL; VIDEOEDITOR_CHECK(M4OSA_NULL != pContext, M4ERR_PARAMETER); ALOGV("VideoEditorMp3Reader_create begin"); /* Context allocation & initialization */ SAFE_MALLOC(pReaderContext, VideoEditorMp3Reader_Context, 1, "VideoEditorMp3Reader"); pReaderContext->mAudioStreamHandler = M4OSA_NULL; pReaderContext->mAudioAu.dataAddress = M4OSA_NULL; pReaderContext->mMaxDuration = 0; *pContext = pReaderContext; cleanUp: if (M4NO_ERROR == err) { ALOGV("VideoEditorMp3Reader_create no error"); } else { ALOGV("VideoEditorMp3Reader_create ERROR 0x%X", err); } ALOGV("VideoEditorMp3Reader_create end"); return err; }
static void create_testfile(void) { FILE *f; char *tmp; size_t i; tst_resm(TINFO, "creating test file of size: %ld", testfile_size); tmp = SAFE_MALLOC(cleanup, pagesize); /* round to page size */ testfile_size = testfile_size & ~((long)pagesize - 1); f = fopen(testfile, "w"); if (!f) { free(tmp); tst_brkm(TBROK | TERRNO, cleanup, "Failed to create %s", testfile); } for (i = 0; i < testfile_size; i += pagesize) if (fwrite(tmp, pagesize, 1, f) < 1) { free(tmp); tst_brkm(TBROK, cleanup, "Failed to create %s", testfile); } fflush(f); fsync(fileno(f)); fclose(f); free(tmp); }
static void child_loop_alloc(unsigned long long alloc_bytes) { unsigned long bytecount = 0; char *mem; tst_res(TINFO, "... child %d starting", getpid()); while (1) { mem = SAFE_MALLOC(chunksize); if (dowrite) do_write_mem(mem, chunksize); if (verbose) tst_res(TINFO, "child %d allocated %lu bytes chunksize is %d", getpid(), bytecount, chunksize); bytecount += chunksize; if (bytecount >= alloc_bytes) break; } if (dowrite) tst_res(TINFO, "... [t=%d] %lu bytes allocated and used in child %d", tst_timeout_remaining(), bytecount, getpid()); else tst_res(TINFO, "... [t=%d] %lu bytes allocated only in child %d", tst_timeout_remaining(), bytecount, getpid()); kill(getppid(), SIGRTMIN); raise(SIGSTOP); exit(0); }
static void child_write(void) { unsigned char *lp, *rp; char buf[bufsz]; struct iovec local, remote; long i; /* get addr from pipe */ SAFE_CLOSE(tst_exit, pipe_fd[1]); SAFE_READ(tst_exit, 0, pipe_fd[0], buf, bufsz); SAFE_CLOSE(tst_exit, pipe_fd[0]); if (sscanf(buf, "%p", &rp) != 1) tst_brkm(TBROK | TERRNO, tst_exit, "sscanf"); lp = SAFE_MALLOC(tst_exit, bufsz + PADDING_SIZE * 2); for (i = 0; i < bufsz + PADDING_SIZE * 2; i++) lp[i] = DEFAULT_CHAR; for (i = 0; i < bufsz; i++) lp[i + PADDING_SIZE] = i % 256; local.iov_base = lp + PADDING_SIZE; local.iov_len = bufsz; remote.iov_base = rp; remote.iov_len = bufsz; tst_resm(TINFO, "child 2: write to the same memory location."); TEST(ltp_syscall(__NR_process_vm_writev, pids[0], &local, 1UL, &remote, 1UL, 0UL)); if (TEST_RETURN != bufsz) tst_brkm(TFAIL | TERRNO, tst_exit, "process_vm_readv"); }
void *api_ui_malloc(size_t size, const UINT32 location) { void* mem_allocated_ptr = NULL; mem_allocated_ptr = SAFE_MALLOC(size, location); //sys_log(LOGSTDOUT, "api_ui_malloc: mem_allocated_ptr = %lx\n", mem_allocated_ptr); return(void*)(mem_allocated_ptr); }
static void child_invoke(void) { char *lp, *rp; char buf[BUFSIZ]; struct iovec local, remote; /* get addr from pipe */ SAFE_CLOSE(tst_exit, pipe_fd[1]); SAFE_READ(tst_exit, 0, pipe_fd[0], buf, BUFSIZ); SAFE_CLOSE(tst_exit, pipe_fd[0]); if (sscanf(buf, "%p", &rp) != 1) tst_brkm(TBROK | TERRNO, tst_exit, "sscanf"); lp = SAFE_MALLOC(tst_exit, len + 1); local.iov_base = lp; local.iov_len = len; remote.iov_base = rp; remote.iov_len = len; tst_resm(TINFO, "child 1: reading string from same memory location."); TEST(test_process_vm_readv(pids[0], &local, 1, &remote, 1, 0)); if (TEST_RETURN != len) tst_brkm(TFAIL | TERRNO, tst_exit, "process_vm_readv"); if (strncmp(lp, tst_string, len) != 0) tst_brkm(TFAIL, tst_exit, "child 1: expected string: %s, " "received string: %256s", tst_string, lp); else tst_resm(TPASS, "expected string received."); }
static void setup(void) { if (tst_parse_int(str_reads, &reads, 1, INT_MAX)) tst_brk(TBROK, "Invalid reads (-r) argument: '%s'", str_reads); if (tst_parse_long(str_max_workers, &max_workers, 1, LONG_MAX)) { tst_brk(TBROK, "Invalid max workers (-w) argument: '%s'", str_max_workers); } if (tst_parse_long(str_worker_count, &worker_count, 1, LONG_MAX)) { tst_brk(TBROK, "Invalid worker count (-W) argument: '%s'", str_worker_count); } if (!root_dir) tst_brk(TBROK, "The directory argument (-d) is required"); if (!worker_count) worker_count = MIN(MAX(tst_ncpus() - 1, 1), max_workers); workers = SAFE_MALLOC(worker_count * sizeof(*workers)); }
static void setup(void) { int i, fd; fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0664); pagesize = getpagesize(); /* Writing 16 pages of random data into this file */ for (i = 0; i < (pagesize / 2); i++) SAFE_WRITE(1, fd, STR, sizeof(STR) - 1); SAFE_FSTAT(fd, &st); file1 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); file2 = SAFE_MMAP(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); SAFE_MUNMAP(file2 + st.st_size - pagesize, pagesize); nonalign = file1 + 100; ptr_addr = SAFE_MALLOC(st.st_size); tmp_addr = (void*)LTP_ALIGN((long)ptr_addr, pagesize); SAFE_CLOSE(fd); tcases_filter(); }
void carray_init(CARRAY *carray, const UINT32 size, const void *init_val, const UINT32 location) { UINT32 pos; CARRAY_INIT_LOCK(carray, LOC_CARRAY_0004); if(0 == size) { carray->data = (void **)0; carray->size = 0; return; } carray->data = (void **)SAFE_MALLOC(sizeof(void *) * size, location); if(carray->data) { /*note: here not call memset to set data area to zero due to finding its unstable*/ for(pos = 0; pos < size; pos ++) { carray->data[ pos ] = (void *)init_val; } carray->size = size; return; } carray->size = 0; return; }
path_t *path_new(void) { path_t *p = NULL; privpath_t *priv = NULL; SAFE_MALLOC(p, 1, path_t); memset(p, 0, sizeof(path_t)); SAFE_MALLOC(priv, 1, privpath_t); memset(priv, 0, sizeof(privpath_t)); p->priv = priv; return p; malloc_error: free(p); free(priv); return NULL; }
/* Preparation: fill in the sum* fields of a path (used for later rapid summing). Return 0 on success, 1 with errno set on failure. */ static int calc_sums(privpath_t *pp) { int i, x, y; int n = pp->len; SAFE_MALLOC(pp->sums, pp->len+1, sums_t); /* origin */ pp->x0 = pp->pt[0].x; pp->y0 = pp->pt[0].y; /* preparatory computation for later fast summing */ pp->sums[0].x2 = pp->sums[0].xy = pp->sums[0].y2 = pp->sums[0].x = pp->sums[0].y = 0; for (i=0; i<n; i++) { x = pp->pt[i].x - pp->x0; y = pp->pt[i].y - pp->y0; pp->sums[i+1].x = pp->sums[i].x + x; pp->sums[i+1].y = pp->sums[i].y + y; pp->sums[i+1].x2 = pp->sums[i].x2 + x*x; pp->sums[i+1].xy = pp->sums[i].xy + x*y; pp->sums[i+1].y2 = pp->sums[i].y2 + y*y; } return 0; malloc_error: return 1; }
static uint8_t *__dupFileName(const uint8_t *root_path) { uint8_t *file_name; MEM_CHECK(file_name = (uint8_t *)SAFE_MALLOC(strlen((char *)root_path) + 1, LOC_RAW_0001)); sprintf((char *)file_name, "%s", (char *)root_path); return (file_name); }
void gdbWriteFreeBlockList(GDatabase *db, GdbFreeBlock *blocks, uint32_t count) { uint32_t listSize; uint8_t *buffer; uint32_t i, counter = 0; offset_t __offset; if (db == NULL || blocks == NULL) { return; } /* Get the total size of the list. */ listSize = sizeof(uint32_t) + count * (sizeof(uint16_t) + sizeof(offset_t)); /* Allocate the buffer for the block list. */ MEM_CHECK(buffer = (uint8_t *)SAFE_MALLOC(listSize, LOC_DB_0006)); gdbPut32(buffer, &counter, count); for (i = 0; i < count; i++) { gdbPut16(buffer, &counter, blocks[i].size); gdbPutOffset(buffer, &counter, blocks[i].offset); } rawFileSeek(db->idxRawFile, DB_FREE_BLOCK_LIST_OFFSET, SEEK_SET); __offset = DB_FREE_BLOCK_LIST_OFFSET; rawFileWrite(db->idxRawFile, __offset, buffer, listSize, 1, LOC_DB_0007); SAFE_FREE(buffer, LOC_DB_0008); }
// // 设置粒子总量 // VOID CGfxBillboard::SetParticleQuota(INT quota) { Renderer()->DestroyVAO(&m_vao); Renderer()->DestroyVBO(&m_vbo); Renderer()->DestroyVBO(&m_ibo); if (quota > 0) { INDEX *indices = (INDEX *)SAFE_MALLOC(6 * quota * sizeof(*indices), MEMTYPE_STACK); { for (INT index = 0; index < quota; index++) { indices[6 * index + 0] = 4 * index + 0; indices[6 * index + 1] = 4 * index + 1; indices[6 * index + 2] = 4 * index + 2; indices[6 * index + 3] = 4 * index + 2; indices[6 * index + 4] = 4 * index + 3; indices[6 * index + 5] = 4 * index + 0; } m_vao = Renderer()->CreateVAO(); m_vbo = Renderer()->CreateVBO(GL_ARRAY_BUFFER, 4 * quota * sizeof(VERTEX), NULL, GL_DYNAMIC_DRAW); m_ibo = Renderer()->CreateVBO(GL_ELEMENT_ARRAY_BUFFER, 6 * quota * sizeof(INDEX), indices, GL_STATIC_DRAW); } SAFE_FREE(indices); } }
DWORD avatars_server_connection::sendUploadAvatarRequest(MCONTACT hContact, WORD wRef, const BYTE *data, size_t datalen) { cookie_avatar *ack = (cookie_avatar*)SAFE_MALLOC(sizeof(cookie_avatar)); if (!ack) return 0; // Failure: out of memory ack->hContact = hContact; DWORD dwCookie = ppro->AllocateCookie(CKT_AVATAR, ICQ_AVATAR_UPLOAD_REQUEST, 0, ack); icq_packet packet; serverPacketInit(&packet, 14 + datalen); packFNACHeader(&packet, ICQ_AVATAR_FAMILY, ICQ_AVATAR_UPLOAD_REQUEST, 0, dwCookie); packWord(&packet, wRef); // unknown, probably reference packWord(&packet, (WORD)datalen); packBuffer(&packet, data, datalen); if (sendServerPacket(&packet)) { ppro->debugLogA("Upload image packet sent."); return dwCookie; } ppro->ReleaseCookie(dwCookie); // failed to send, free resources return 0; }
static char *make_server_reply(int size) { char *send_msg = SAFE_MALLOC(NULL, size); memset(send_msg, server_byte, size - 1); send_msg[0] = start_byte; send_msg[size - 1] = end_byte; return send_msg; }