コード例 #1
0
ファイル: unity_fixture.c プロジェクト: mindw/Unity
void* unity_realloc(void * oldMem, size_t size)
{
    Guard* guard = (Guard*)oldMem;
//    char* memAsChar = (char*)oldMem;
    void* newMem;

    if (oldMem == 0)
        return unity_malloc(size);

    guard--;
    if (isOverrun(oldMem))
    {
        release_memory(oldMem);
        /*DX_PATCH for jumless version*/
        UnityPrint("Buffer overrun detected during realloc()", unity_p);
        return 0;
    }

    if (size == 0)
    {
        release_memory(oldMem);
        return 0;
    }

    if (guard->size >= size)
        return oldMem;

    newMem = unity_malloc(size);
    memcpy(newMem, oldMem, guard->size);
    unity_free(oldMem);
    return newMem;
}
コード例 #2
0
ファイル: unity_fixture.c プロジェクト: 2asoft/freebsd
void* unity_realloc(void * oldMem, size_t size)
{
    Guard* guard = (Guard*)oldMem;
//    char* memAsChar = (char*)oldMem;
    void* newMem;

    if (oldMem == 0)
        return unity_malloc(size);

    guard--;
    if (isOverrun(oldMem))
    {
        release_memory(oldMem);
        TEST_FAIL_MESSAGE("Buffer overrun detected during realloc()");
    }

    if (size == 0)
    {
        release_memory(oldMem);
        return 0;
    }

    if (guard->size >= size)
        return oldMem;

    newMem = unity_malloc(size);
    memcpy(newMem, oldMem, guard->size);
    unity_free(oldMem);
    return newMem;
}
コード例 #3
0
ファイル: test.c プロジェクト: mikenorthorp/binaryBuddy
// Main testing
int main( int argc, char **argv )
{
    printf("Running basic tests, you can run your own these are just examples..\n");
    printf("Initializing memory to 2048bytes\n");
    start_memory(2048);

    // Attempt to get memory
    printf("The following test the get memory function\n");
    printf("The address for 2bytes of memory is %p\n", get_memory(2));
    int testSize = sizeof(testStruct);
    printf("Size is %d", testSize);
    testStruct *test1 = get_memory(testSize);
    printf(" and address is %p\n", (void *)test1);

    printf("Size is %d", testSize);
    testStruct *test2 = get_memory(testSize);
    printf(" and address is %p\n", (void *)test2);

    printf("Size is %d", testSize);
    testStruct *test3 = get_memory(testSize);
    printf(" and address is %p\n", (void *)test3);

    // Test release memory on third struct
    release_memory(test3);

    // Test end_memory on remaining structs
    printf("Testing release memory on remaining stuff, should display leaks and free everything\n");
    end_memory();


    printf("End of testing\n");
    // Exit main
    return 1;
}
コード例 #4
0
ファイル: metafile.cpp プロジェクト: niklaus520/HyberScaner
//种子文件解析模块
int parse_metafile(const char * metafile_name)
{
	if(metafile_name == NULL)
		return -1;
	//读取种子文件到缓冲区
	if(readfile_tobuffer(metafile_name) < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
	//保存tracker的url地址到链表
	if(save_tracker_list() < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
	//获取文件名和文件大小,如果是多文件获取的是目录名
	if(get_filepath_name() < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
    else {
        test2();
    }
	//获取每个piece的长度
	if(get_piece_length() < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
	//获取pieces的hash值,保存到缓冲区中
	if(get_pieces_hash() < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
	// 计算info_hash的值
	if(cal_info_hash() < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
	//生成唯一的一个peer_id来标识客户端
	if(get_peer_id() < 0){
		printf("error : %s:%d\n",__FILE__,__LINE__);return -1;}
	//释放动态内存
	release_memory();
	return 0;
}
コード例 #5
0
ファイル: program11_06.c プロジェクト: NoMan2000/c-prog
int main(void)
{
  Family *first = NULL;                // Pointer to first person      
  Family *current = NULL;              // Pointer to current person    
  Family *last = NULL;                 // Pointer to previous person   
  char more = '\0';                    // Test value for ending input  

  while(true)
  {
    printf_s("\nDo you want to enter details of a%s person (Y or N)? ",
                                        first != NULL?"nother" : "");
    scanf_s(" %c", &more, sizeof(more));
    if(tolower(more) == 'n')
      break;

    current = get_person();

    if(first == NULL)
    {
      first = current;                // Set pointer to first Family  
      last = current;                 // Remember for next iteration  
    }
    else
    {
      last->next = current;   // Set next address for previous Family 
      current->previous = last;   // Set previous address for current 
      last = current;             // Remember for next iteration      
    }
  }

  show_people(true, first, last); // Tell them what we know 
  release_memory(first);
  first = last = NULL;
  return 0;
}
コード例 #6
0
 std::shared_ptr<fileio_impl::general_fstream_sink> cache_block::write_to_file() {
   ASSERT_TRUE(filename.empty());
   filename = get_temp_name_prefer_hdfs();
   logstream(LOG_DEBUG) << "Flushing to " << filename << std::endl;
   auto fout = std::make_shared<fileio_impl::general_fstream_sink>(filename);
   if (data) fout->write(data, size);
   release_memory();
   return fout;
 }
コード例 #7
0
ファイル: unity_fixture.c プロジェクト: 2asoft/freebsd
void unity_free(void * mem)
{
    int overrun = isOverrun(mem);//strcmp(&memAsChar[guard->size], end) != 0;
    release_memory(mem);
    if (overrun)
    {
        TEST_FAIL_MESSAGE("Buffer overrun detected during free()");
    }
}
コード例 #8
0
ファイル: cdmake.c プロジェクト: HBelusca/NasuTek-Odyssey
void error_exit ( const char* fmt, ... )
{
  va_list arg;

  va_start(arg, fmt);
  vprintf(fmt, arg);
  va_end(arg);
  printf("\n");
  if (cd.file != NULL)
    fclose(cd.file);
  release_memory();
  exit(1);
}
コード例 #9
0
static int __devexit	touch_tool_remove( struct platform_device *pdev )
{

	struct touch_tool_data	*tool_data = dev_get_drvdata( &pdev->dev );

	control_file_node_unregister( tool_data->file_node_class );

	release_command_resource( &tool_data->command );

	release_memory( tool_data );

	return	0;

}
コード例 #10
0
ファイル: main.c プロジェクト: DLuCJ/miscellaneous
int main (void)
{

    PERSON *head = NULL;
 
    
    head = createList();
    
    print_list(head);
    
    release_memory(head);

    printf("Done\n");
    return 0;
}
コード例 #11
0
ファイル: unity_fixture.c プロジェクト: 2trill2spill/nextgen
void* unity_realloc(void* oldMem, size_t size)
{
    Guard* guard = (Guard*)oldMem;
    void* newMem;

    if (oldMem == NULL) return unity_malloc(size);

    guard--;
    if (isOverrun(oldMem))
    {
        release_memory(oldMem);
        UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during realloc()");
    }

    if (size == 0)
    {
        release_memory(oldMem);
        return NULL;
    }

    if (guard->size >= size) return oldMem;

#ifdef UNITY_EXCLUDE_STDLIB_MALLOC /* Optimization if memory is expandable */
    if (oldMem == unity_heap + heap_index - guard->size - sizeof(end) &&
        heap_index + size - guard->size <= UNITY_INTERNAL_HEAP_SIZE_BYTES)
    {
        release_memory(oldMem); /* Not thread-safe, like unity_heap generally */
        return unity_malloc(size); /* No memcpy since data is in place */
    }
#endif
    newMem = unity_malloc(size);
    if (newMem == NULL) return NULL; /* Do not release old memory */
    memcpy(newMem, oldMem, guard->size);
    release_memory(oldMem);
    return newMem;
}
コード例 #12
0
ファイル: unity_fixture.c プロジェクト: 2trill2spill/nextgen
void unity_free(void* mem)
{
    int overrun;

    if (mem == NULL)
    {
        return;
    }

    overrun = isOverrun(mem);
    release_memory(mem);
    if (overrun)
    {
        UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during free()");
    }
}
コード例 #13
0
ファイル: master.c プロジェクト: ouyangjn/leviathan
int
master_exit(void)
{
    /* Determine if any enclaves are running - if so, we cannot exit */
    struct enclave_info * enclaves = NULL;
    uint32_t num_enclaves;

    enclaves = hobbes_get_enclave_list(&num_enclaves);
    if (enclaves == NULL) {
	ERROR("Could not retrieve enclave list\n");
	return -1;
    }

    switch (num_enclaves) {
	case 0:
	    ERROR("0 active enclaves: the master DB has been corrupted\n");
	    return -1;

	case 1:
	    break;
	
	default:
	    ERROR("Cannot stop Leviathan: there are %d active enclaves that must be destroyed first\n",
		num_enclaves - 1);
	    free(enclaves);
	    return -1;
    }

    /* Ensure that the enclave is just the master */
    if (enclaves[0].type != MASTER_ENCLAVE) {
	ERROR("Only 1 enclave running, but it is not the master. Cannot stop Leviathan\n");
	free(enclaves);
	return -1;
    }

    free(enclaves);

    /* Re-online all resources */
    release_memory();
    release_cpus();

    /* Ensure all resources are unlocked */
    unreserve_memory();
    unreserve_cpus();

    return 0;
}
コード例 #14
0
 void cache_block::clear() {
   if (data) {
     logstream(LOG_DEBUG) << "Releasing cache ID " << cache_id << std::endl;
     release_memory();
   } else if (!filename.empty()) {
     logstream(LOG_DEBUG) << "Releasing cache ID " << cache_id << std::endl;
     // delete disk temp file
     try {
       logstream(LOG_DEBUG) << "Deleting cached file " << filename << std::endl;
       delete_temp_file(filename);
     } catch (...) {
       logstream(LOG_WARNING) << "Failed to delete temporary file: " 
                              << filename << std::endl;
     }
     filename.clear();
   }
 }
コード例 #15
0
bool os::is_allocatable(size_t bytes) {
#ifdef _LP64
  return true;
#else
  if (bytes < 2 * G) {
    return true;
  }

  char* addr = reserve_memory(bytes, NULL);

  if (addr != NULL) {
    release_memory(addr, bytes);
  }

  return addr != NULL;
#endif // _LP64
}
コード例 #16
0
ファイル: fpmain.c プロジェクト: Ch3ck/Khati-Khati
/*
 * Main(): Executes FP Growth algorithm.
 */
int
main(int argc, char **argv)
{

	num_freq_sets = size = colcnt = num_oflines = num_updates = 0;

	/** Create instance of class FPTree */
	fptreePtr fptree;

	/** Read data to be mined from file */
	printf("\nReading Input Data..");
	input_dataset();

	/** Reorder and prune input data according to frequency of single attr */
	printf("\nOrdering Input Data..");
	order_input_data();
	printf("\nRecasting input Data pruning infrequent items");
	recast_data_prune_unsupported();
	printf("\nPrinting frequent-1 itemsets");
	gen_freq_one_itemsets();/** Prints freq-1 itemsets */


    /** Build initial FP-tree */
	printf("\nBuilding FP tree");
	create_fptree(fptree);	/* skip invalid elements(-1) */
	printf("\nPrinting FP tree.");
	out_fptree(fptree);	/* need to print the tree */

	/** Mine FP-tree */
	printf("\nMining FP tree");
	start_mining(fptree);/** frequent sets are generated and stored to file here. */
	printf("\nReleasing memory consumption of tree.");
	out_fptree_storage(fptree->root);
	release_memory(fptree);	/** Frees all used memory */

	return 0;
}
コード例 #17
0
static int __devinit	touch_tool_probe( struct platform_device *pdev )
{

	struct synaptics_rmi4_data	*rmi_data = ( struct synaptics_rmi4_data* )pdev->dev.platform_data;

	struct touch_tool_data		*tool_data;

	if( !rmi_data )
	{

		printk( "TTUCH : The pointer of RMI data is NULL\n" );

		return	-ENOMEM;

	}

	if( !( tool_data = allocate_memory() ) )
	{

		printk( "TTUCH : allocate Memory failed\n" );

		return	-ENOMEM;

	}

	if( !create_command_string_list( &tool_data->string ) )
	{

		printk( "TTUCH : Create command failed\n" );

		release_memory( tool_data );

		return	-EINVAL;

	}

	tool_data->rmi_data = rmi_data;

	if( load_command( &tool_data->command, get_load_command_pointer(), get_load_command_counter() ) )
	{

		struct control_node_load	file_node;

		// Create file node in sys/class/touch/rmi4
		file_node.class_name = "touch", file_node.device_name = "rmi4";

		file_node.file_node_data = tool_data, file_node.control_read = tool_command, file_node.control_write = tool_control, file_node.info_read = tool_info;

		tool_data->file_node_class	= control_file_node_register( &file_node );

		dev_set_drvdata( &pdev->dev, tool_data );

		info_print( INFO_BUFFER_INIT, NULL, tool_data->info_buffer, INFO_BUFFER_SIZE );

		INIT_LIST_HEAD( &tool_data->descriptor_list );

		get_page_description( tool_data );

		get_touch_ic_info( tool_data, log_print );
 
		printk( "TTUCH : Touch tool driver is ready\n" );

		return	0;

	}

	release_memory( tool_data );

	return	-EINVAL;

}
コード例 #18
0
ファイル: folder.c プロジェクト: arcfide/Unicode-NN
int
folder_menu(char *path, int mode)
{
    FILE           *folder;
    register article_header *ah;
    news_header_buffer dgbuf;
    char            buffer[256];
    int             more, length, re, menu_cmd, was_raw;
    memory_marker   mem_marker;
    group_header    fake_group;
    int             cc_save;
    char            folder_name[FILENAME], folder_file[FILENAME];
    int             orig_layout;
    char           *orig_hdr_lines;

    orig_layout = fmt_linenum;
    orig_hdr_lines = header_lines;

    strcpy(folder_name, path);
    fake_group.group_name = folder_name;
    fake_group.kill_list = NULL;
    if (!expand_file_name(folder_file, folder_name, 1))
	return ME_NO_REDRAW;
    fake_group.archive_file = path = folder_file;
    fake_group.next_group = fake_group.prev_group = NULL;
    fake_group.group_flag = G_FOLDER | G_FAKED;
    fake_group.master_flag = 0;
    fake_group.save_file = NULL;
    current_group = NULL;
    init_group(&fake_group);

    folder = open_file(path, OPEN_READ);
    if (folder == NULL) {
	msg("%s not found", path);
	return ME_NO_REDRAW;
    }
    switch (get_folder_type(folder)) {
	case 0:
	    msg("Reading: %-.65s", path);
	    break;
	case 1:
	case 2:
	    msg("Reading %s folder: %-.50s",
		current_folder_type == 1 ? "mail" : "mmdf", path);
	    break;
	default:
	    msg("Folder is empty");
	    fclose(folder);
	    return ME_NO_REDRAW;
    }
    rewind(folder);

    was_raw = no_raw();
    s_keyboard = 0;

    current_group = &fake_group;

    mark_memory(&mem_marker);

    ah = alloc_art();

    more = 1;
    while (more && (more = get_digest_article(folder, dgbuf)) >= 0) {
	if (s_keyboard)
	    break;

	ah->a_number = 0;
	ah->flag = A_FOLDER;
	ah->attr = 0;

	ah->lines = digest.dg_lines;

	ah->hpos = digest.dg_hpos;
	ah->fpos = digest.dg_fpos;
	ah->lpos = digest.dg_lpos;

	if (digest.dg_from) {
	    length = pack_name(buffer, digest.dg_from, Name_Length);
	    ah->sender = alloc_str(length);
	    strcpy(ah->sender, buffer);
	    ah->name_length = length;
	    if (mode == 1)
		fold_string(ah->sender);
	} else {
	    ah->sender = "";
	    ah->name_length = 0;
	}

	if (digest.dg_subj) {
	    length = pack_subject(buffer, digest.dg_subj, &re, 255);
	    ah->replies = re;
	    ah->subject = alloc_str(length);
	    strcpy(ah->subject, buffer);
	    ah->subj_length = length;
	    if (mode == 1 && length > 1)
		fold_string(ah->subject + 1);
	} else {
	    ah->replies = 0;
	    ah->subject = "";
	    ah->subj_length = 0;
	}

	ah->t_stamp = digest.dg_date ? pack_date(digest.dg_date) : 0;

	add_article(ah);
	ah = alloc_art();
    }

    fclose(folder);

    if (s_keyboard) {
	menu_cmd = ME_NO_REDRAW;
    } else if (n_articles == 0) {
	msg("Not a folder (no article header)");
	menu_cmd = ME_NO_REDRAW;
    } else {
	if (n_articles > 1) {
	    clrdisp();
	    prompt_line = 2;
	    if (mode == 0 && !dont_sort_folders)
		sort_articles(-1);
	    else if (mode == 1) {
		article_number  n;
		for (n = 0; n < n_articles; n++) {
		    ah = articles[n];
		    if (n == 0)
			ah->flag |= A_ROOT_ART;
		    else if (strcmp(ah->sender, articles[n - 1]->sender) == 0)
			articles[n - 1]->flag |= A_NEXT_SAME;
		    else
			ah->flag |= A_ROOT_ART;
		}
		bypass_consolidation = consolidated_manual ? 2 : 1;
	    } else
		no_sort_articles();
	} else
	    no_sort_articles();

	cc_save = cancel_count;
	cancel_count = 0;
	if (mode == 1) {
	    fmt_linenum = -1;
	    header_lines = "*";
	}
reenter_menu:
	ignore_fancy_select = 1;
	menu_cmd = menu(folder_header);
	ignore_fancy_select = 0;

	if (mode == 0 && cancel_count) {
	    register article_number cur;

	    cancel_count = 0;
	    for (cur = 0; cur < n_articles; cur++) {
		if (articles[cur]->attr == A_CANCEL)
		    cancel_count++;
	    }
	}
	if (mode == 0 && cancel_count) {
	    clrdisp();
	    tprintf("\rFolder: %s\n\rFile:   %s\n\n\r", folder_name, folder_file);
	    if (cancel_count == n_articles)
		tprintf("Cancel all articles and remove folder? ");
	    else
		tprintf("Remove %d article%s from folder? ",
			cancel_count, plural((long) cancel_count));
	    fl;

	    switch (yes(1)) {
		case 1:
		    tprintf("\n\n");
		    if (cancel_count == n_articles) {
			if (unlink(group_path_name) < 0 &&
			    nn_truncate(group_path_name, (off_t) 0) < 0) {
			    tprintf("\rCould not unlink %s\n\r", group_path_name);
			    any_key(0);
			}
		    } else
			rewrite_folder();
		    break;
		case 0:
		    break;
		default:
		    goto reenter_menu;
	    }
	}
	cancel_count = cc_save;
    }

    release_memory(&mem_marker);
    if (fmt_linenum == -1) {
	fmt_linenum = orig_layout;
	header_lines = orig_hdr_lines;
    }
    if (was_raw)
	nn_raw();

    return menu_cmd;
}
コード例 #19
0
int
main( int argc, char **argv )
{

    /* Take in the threads from command line using argv and create
       that many threads */
    int numThreads;
    if (argc >= 2)
    {
        numThreads = atoi(argv[1]);
    }
    else
    {
        printf("Please put the number of threads you want as an argument\n");
        return 1;
    }

    // Define threads array
    pthread_t puzzleThread[numThreads];
    fill_t fillArray[numThreads];

    // Define values to get from input for grid and piece list
    int return_value = 0;
    piece_list_t piece_list;
    grid_t grid;
    int i;

    // Get input from STDIN for piece list and grid
    if (get_input( &grid, &piece_list ))
    {

        /* Create all of the structs to pass in with the threads */
        for (i = 0; i < numThreads; i++)
        {
            fillArray[i].grid = &grid;
            fillArray[i].piece_list = &piece_list;

            // Pick which corner to put the thread in, and to go which direction
            if (i % 8 == 0) // Top left
            {
                fillArray[i].start_col = 0;
                fillArray[i].start_row = 0;
                fillArray[i].inc_index = GO_LEFT_TO_RIGHT;
            }
            else if (i % 8 == 1) // Bottom right
            {
                fillArray[i].start_col = grid.numcols - 1;
                fillArray[i].start_row = grid.numrows - 1;
                fillArray[i].inc_index = GO_RIGHT_TO_LEFT;
            }
            else if (i % 8 == 2) // Top right
            {
                fillArray[i].start_col = grid.numcols - 1;
                fillArray[i].start_row = 0;
                fillArray[i].inc_index = GO_RIGHT_TO_LEFT;
            }
            else if ( i % 8 == 3) // Bottom left
            {
                fillArray[i].start_col = 0;
                fillArray[i].start_row = grid.numrows - 1;
                fillArray[i].inc_index = GO_LEFT_TO_RIGHT;
            }
            else if ( i % 8 == 4) // Top left top-bottom
            {
                fillArray[i].start_col = 0;
                fillArray[i].start_row = 0;
                fillArray[i].inc_index = GO_TOP_TO_BOTTOM;
            }
            else if ( i % 8 == 5) // Bottom right bottom-top
            {
                fillArray[i].start_col = grid.numcols - 1;
                fillArray[i].start_row = grid.numrows - 1;
                fillArray[i].inc_index = GO_BOTTOM_TO_TOP;
            }
            else if ( i % 8 == 6) // Top right top-bottom
            {
                fillArray[i].start_col = grid.numcols - 1;
                fillArray[i].start_row = 0;
                fillArray[i].inc_index = GO_TOP_TO_BOTTOM;
            }
            else if ( i % 8 == 7) // Bottom left bottom-top
            {
                fillArray[i].start_col = 0;
                fillArray[i].start_row = grid.numrows - 1;
                fillArray[i].inc_index = GO_BOTTOM_TO_TOP;
            }
        }

        /* Create all of the threads at once */
        for (i = 0; i < numThreads; i++)
        {
            // Create a single puzzle thread to solve starting in top left
            if (pthread_create(&puzzleThread[i], NULL, &puzzleThreadSolver, &fillArray[i]))
            {
                fprintf(stderr, "Error creating thread\n");
            }
        }

        /* End Thread creation */

        // Wait for threads to finish that are created and join them to main
        for (i = 0; i < numThreads; i++)
        {
            // Wait for puzzle threads to end
            if (pthread_join(puzzleThread[i], NULL))
            {
                fprintf(stderr, "Error joining thread\n");
                return_value = 2;
            }
        }

        /* Show what the puzzle came out to be. */

        print_grid( &grid );

        release_memory( &grid, &piece_list );
    }

    // Exit the program with return value
    return return_value;
}