Example #1
0
/** 
 * Load and extract a file with number *.spr with into 'image' structure
 * @param fname filename The file *.spr (ie "STAR%1d.SPR") 
 * @param num The file number from 0 to n
 * @param img Pointer to destination 'image' structure 
 * @param num_of_sprites Number different sprites
 * @param num_of_anims Number of animations for a same sprite
 * @return TRUE if it completed successfully or FALSE otherwise
 */
bool
image_load_num (const char *fname, Sint32 num, image * img,
                Uint32 num_of_sprites, Uint32 num_of_anims)
{
  char *data;
  char *file = loadfile_num (fname, num);
  if (file == NULL)
    {
      return FALSE;
    }
  data = images_read (img, num_of_sprites, num_of_anims, file, num_of_anims);
  free_memory (file);
  if (data == NULL)
    {
      return FALSE;
    }
  return TRUE;
}
Example #2
0
/* do some cleanup before we exit */
void cleanup(void)
{
	/* free event queue data */
	destroy_event_queue();

	/* unload modules */
	if (verify_config == FALSE) {
		neb_free_callback_list();
		neb_unload_all_modules(NEBMODULE_FORCE_UNLOAD, (sigshutdown == TRUE) ? NEBMODULE_NEB_SHUTDOWN : NEBMODULE_NEB_RESTART);
		neb_free_module_list();
		neb_deinit_modules();
	}

	/* free all allocated memory - including macros */
	free_memory(get_global_macros());
	close_log_file();

	return;
}
Example #3
0
char* FailableMemoryAllocator::alloc_memory(size_t size, const char* file, int line)
{
    currentAllocNumber_++;
    LocationToFailAllocNode* current = head_;
    LocationToFailAllocNode* previous = NULLPTR;

    while (current) {
      if (current->shouldFail(currentAllocNumber_, file, line)) {
        if (previous) previous->next_ = current->next_;
        else head_ = current->next_;

        free_memory((char*) current, __FILE__, __LINE__);
        return NULLPTR;
      }
      previous = current;
      current = current->next_;
    }
    return TestMemoryAllocator::alloc_memory(size, file, line);
}
Example #4
0
File: main.c Project: isbit/INF1060
/**
 * reads input from given stdin, and compares the content of the string
 * @param read
 *
 */
void command_read(char *read) {
    int id = -1;
    person *pers = NULL;
    char name[BUF_LEN]; /*static allocation of username*/
    memset(name, 0, sizeof (name));

    if (strcmp(read, "exit") == 0) {
        puts("to exit");
        free(command_line);

        if (!is_empty()) {
            free_memory();
        }

        exit(1);
    } else if (strstr(read, "add") != NULL) {
        if (sscanf(read, "add %d %[^\t\n]", &id, name) == 2) {
            pers = (person *) stack_malloc(sizeof (person));
            pers->id = id;
            strcpy(pers->name, name);
            enqueue(pers);
        }
    } else if (strcmp(read, "print") == 0) {
        print_q();
    } else if (strstr(read, "find") != NULL) {
        if (sscanf(read, "find %s", name) == 1) {
            if (search(name) > -1) {
                printf("found person: %s\n", name);
            } else {
                puts("person not found, try to type in full name");
            }
        }
    } else if (strstr(read, "remove") != NULL) {
        if (sscanf(read, "remove %s", name) == 1) {
            if (remove_node(name) > -1) {
                printf("removed: %s\n", name);
            } else {
                puts("person not found, try to type in full name or it doesn't exists");
            }
        }
    }

}
Example #5
0
/* cleanup */
static void do_cleanup(void) {

	/* free memory */
	free_memory();

	/* close the command file if its still open */
	if (command_file_fp != NULL)
		close_command_file();

	/*** CLEAR SENSITIVE INFO FROM MEMORY ***/

	/* overwrite password */
	clear_buffer(password, sizeof(password));

	/* disguise decryption method */
	decryption_method = -1;

	return;
}
Example #6
0
void OutputWaveOut::uninitialize()
{
    if (dev)
    {
        waveOutReset(dev); // reset the device
        while (ScheduledBlocks > 0);
            Sleep (10);

        while (PlayedWaveHeadersCount > 0)         // free used blocks ...
            free_memory ();

        waveOutReset (dev);      // reset the device
        waveOutClose (dev);      // close the device
        dev = 0;
    }

    DeleteCriticalSection (&cs);
    return;
}
Example #7
0
void mux_output_list_remove(MuxOutputList *list, MuxPipe pipe)
{
    MuxOutputNode *current_node = list->head;
    MuxOutputNode *previous_node = NULL;

    /* Search list for our in_pin to remove it */
    while (NULL != current_node) {
	int current_output = current_node->out_pin;
	int channel_num = current_node->channel_num;

	if (current_output == pipe.out_pin) {
	    mux_channel_list_remove(&current_node->channels, pipe);

	    /* Need to adjust the current channel */
	    current_node->current_channel = find_channel_node(&current_node->channels,
							      channel_num);

	    if (NULL == current_node->channels.head) {
		/* No more channels, need to remove this output */
		if (NULL != previous_node) {
		    previous_node->next = current_node->next;
		}
		
		/* Adjust the head and tail if necessary */
		if (current_node == list->head) {
		    list->head = list->head->next;
		}
		
		if (current_node == list->tail) {
		    list->tail = previous_node;
		}

		free_memory(current_node);
	    }

	    return;
	}

	previous_node = current_node;
	current_node = current_node->next;
    }
}
Example #8
0
void add_to_growable_string (agent* thisAgent, growable_string *gs, 
							 const char *string_to_add) {
  size_t current_length, length_to_add, new_length, new_memsize;
  growable_string New;

  current_length = length_of_growable_string(*gs);
  length_to_add = strlen (string_to_add);
  new_length = current_length + length_to_add;
  if (new_length + 1 > static_cast<size_t>(memsize_of_growable_string(*gs))) {
    new_memsize = memsize_of_growable_string(*gs);
    while (new_length + 1 > new_memsize) new_memsize = new_memsize * 2;
    New = allocate_memory (thisAgent, new_memsize + 2*sizeof(int *), STRING_MEM_USAGE);
    memsize_of_growable_string(New) = static_cast<int>(new_memsize);
    strcpy (text_of_growable_string(New), text_of_growable_string(*gs));
    free_memory (thisAgent, *gs, STRING_MEM_USAGE);
    *gs = New;
  }
  strcpy (text_of_growable_string(*gs)+current_length, string_to_add);
  length_of_growable_string(*gs) = static_cast<int>(new_length);
}
void allocator<T>::deallocate(pointer p, size_type n)
{
	const size_type nb = n * sizeof(T);
#	if DEBUG_SMA_TRACE_INTERFACE
	std::cout << "dealloc " << nb << " bytes (n=" << n << ", pointer=" << static_cast<void *>(p) <<")" << std::endl;
#	endif
	assert(nb > 0);
	const size_type pos = calc_pos(memstart, p);
	assert(0 <= pos && pos < memfree->size());
	auto mask = create_mask(nb, memfree->size()) << pos;
#	if DEBUG_SMA_TRACE_MEMALLOCATION
	std::cout << "freeed memory: " << mask.count() << " bytes -> "
		  << (memfree->count() + mask.count()) << " bytes free."
		  << std::endl;
#	endif
	*memfree = free_memory(*memfree, std::move(mask));
#	if DEBUG_SMA_TRACE_MEMALLOCATION
	print_free_memory();
#	endif
}
Example #10
0
/* Thread function that wait from parser
 * to end , and uses the tlp library to
 * deserialize the structures. After that it
 * paints the structures to the gtk tree. */
void *read_structures() {
    Shared *shmem;
    // create a new shared segment
    shmid = shmget(IPC_PRIVATE, sizeof(Shared), IPC_CREAT|0777);
    // attach shared memory segment to the address space
    shmem = (Shared *)shmat(shmid, NULL, 0);
    // destroy segment after the last process detaches
    shmctl(shmid, IPC_RMID, NULL);

    while(1) {
        // wait for the process to signal
        shmem->rdy = 0;
        while(shmem->rdy == 0) {}
        // deserialize the structures
        load_structures();
        create_and_fill_tree();
        free_memory();
    }
    return 0;
}
Example #11
0
int
WIN_Audio_close ()
{
	if ( dev != NULL ) {

		while ( ScheduledBlocks > 0 ) {
			Sleep (ScheduledBlocks);
			while ( PlayedWaveHeadersCount > 0 )         // free used blocks ...
				free_memory ();
		}

		waveOutReset (dev);      // reset the device
		waveOutClose (dev);      // close the device
		dev = NULL;
	}

	DeleteCriticalSection ( &cs );
	ScheduledBlocks = 0;
	return 0;
}
Example #12
0
int main(int argc, char **argv)
{
    int num_of_hospitals = 0;
    hospital_t *hosp;

    if (read_argument(argc, argv) == 'h') {
        print_manual();
        return 0;
    }

    hosp = read_information_for_hospitals(&num_of_hospitals);
    printf("Do you want to see the information of hospitals?");
    if(confirm_choice()) {
        print_information_of_hospitals(hosp, num_of_hospitals);
    }  
    while (add_patient(hosp, num_of_hospitals));
    print_information_of_hospitals(hosp, num_of_hospitals);

    free_memory(hosp, num_of_hospitals);
    return 0;
}
Example #13
0
/** 
 * Decompress pcx file and convert to 8 bits (no change),
 * or 16 bits or 24 bits
 * @param filename the file which should be loaded
 * @return file data buffer pointer
 */
char *
load_pcx_file (const char *filename)
{
  char *buffer;
  bitmap_desc *gfx = load_pcx (filename);
  if (gfx == NULL)
    {
      return NULL;
    }
  if (bytes_per_pixel > 0)
    {
      if (!convert_16_or_24 (gfx))
        {
          LOG_ERR ("convert_16_or_24() failed!");
          return NULL;
        }
    }
  buffer = gfx->pixel;
  free_memory ((char *) gfx);
  return buffer;
}
int main ()
{
    int n,i,a;
    printf("Inicializando arvore. Quantos valores deseja entrar? ");
    scanf("%d",&n);
    while (n<1)//Previne erros e garante que pelo menos 1 item estara na arvore.
    {
        printf("Entre com pelo menos um numero. Quantos valores deseja entrar? ");
        scanf("%d",&n);
    }
    printf("Entre com os numeros:\n");
    for (i=0;i<n;i++)//preenche a arvore.
    {
        scanf("%d",&a);
        adicionar (a);
    }
    i=0;
    while (i!=1)
        i=menu();//chama o menu e retorna 1 quando quiser sair.
    free_memory(root);//desaloca a memoria.
}
Example #15
0
int main (int argc, char **argv)
{
	process_args (&argc, &argv);
	set_field_n_cond (argc, argv);
	calc_hash_size ();
	create_hash ();
	postproc_cond ();
	process_output_fields ();
	read_summaries ();

	free_memory ();

	if (!error || found_cnt){
		return 0;
	}else{
		if (verbose)
			fprintf (stderr, "No matches found\n");

		return 1;
	}
}
Example #16
0
// query4 $inputfile $datapath
int main(int argc, char *argv[]){
	
	// initialization
	input_file_name = argv[1];
	dir_name = argv[2];
	dir_name_len = (int)strlen(argv[2]);
	file_name_max_len = dir_name_len + 50;
	data_file_name = new char [file_name_max_len];
	
	cnt_data_lines("person.csv", &personcnt);
	cnt_data_lines("forum.csv", &forumcnt);
	cnt_data_lines("tag.csv", &tagcnt);
	person_in_induced_graph = new char[personcnt];

#if DEBUG
	printf("cnt done.\n");
#endif
	read_edges();
	convert2undirected();
#if DEBUG
	printf("start forums.\n");
#endif
	read_forums();
	read_tags();
	
	read_queries();
#if DEBUG
	printf("read Q done\n");
#endif
	
	// solve
	freopen("query4.out", "w", stdout);
	for (vector < pair<int, int> > :: iterator it=queries.begin(); it!=queries.end(); it++)
		query(it->first, it->second);
	fclose(stdout);
	
	free_memory();
	return 0;
}
Example #17
0
/**
 * Allocate memory and load a file there
 * @param filename the file which should be loaded
 * @param fsize pointer on the size of file which will be loaded
 * @return file data buffer pointer
 */
char *
load_absolute_file (const char *const filename, Uint32 * const filesize)
{
  size_t fsize;
  FILE *fstream;
  char *buffer;
  fstream = fopen (filename, "r");
  if (fstream == NULL)
    {
      LOG_ERR ("can't open file  %s (%s)", filename, strerror (errno));
      return NULL;
    }
  fsize = get_file_size (fstream);
  (*filesize) = fsize;
  if (fsize == 0)
    {
      fclose (fstream);
      LOG_ERR ("file %s is empty!", filename);
      return NULL;
    }
  buffer = memory_allocation (fsize);
  if (buffer == NULL)
    {
      LOG_ERR ("not enough memory to allocate %i bytes!",
               filename, (Sint32) fsize);
      fclose (fstream);
      return NULL;
    }
  if (fread (buffer, sizeof (char), fsize, fstream) != fsize)
    {
      free_memory (buffer);
      LOG_ERR ("can't read file \"%s\" (%s)", filename, strerror (errno));
      fclose (fstream);
      return NULL;
    }
  fclose (fstream);
  LOG_DBG ("file \"%s\" was loaded in memory", filename);
  return buffer;
}
Example #18
0
int main(int argc, char **argv) {

    if(argc < 2) {
        printf("Especifique o arquivo com o codigo\n");
        exit(0);
    }

    init_memory();

    init_stack();

    loadcode(argv[1]);

    init_cpu();

    while(cpu_cycle());

    memory_dump();

    free_memory();
    return 0;
}
Example #19
0
int load_ptbl(struct storage_specific_functions *storage, u8 silent)
{
	u32 sector_sz = storage->get_sector_size();
	u64 ptbl_sectors = 0;
	int i = 0, r = 0;

	struct ptable *gpt;
	int gpt_size = sizeof(struct ptable);

	gpt =  (struct ptable *) alloc_memory(gpt_size);
	if (!gpt) {
		r = 0;
		goto fail;
	}

	ptbl_sectors = (u64)(gpt_size / sector_sz);

	r = storage->read(0, ptbl_sectors, (void *)gpt);
	if (r != 0) {
		printf("error reading GPT\n");
		return r;
		goto fail;
	}

	if (memcmp(gpt->header.magic, "EFI PART", 8)) {
		if (!silent)
			printf("efi partition table not found\n");
		r = -1;
		goto fail;
	}

	for (i = 0; i < EFI_ENTRIES; i++)
		import_efi_partition(&gpt->entry[i], i, silent);

fail:
	free_memory((void *)gpt);
	return r;
}
Example #20
0
/*Run ACC with Lock/unlock */
void run_acc_with_lock(int rank, WINDOW type)
{
    int size, i;
    MPI_Aint disp = 0;
    MPI_Win     win;

    for (size = 0; size <= MAX_SIZE; size = (size ? size * 2 : 1)) {
        allocate_memory(rank, sbuf_original, rbuf_original, &sbuf, &rbuf, &sbuf, size, type, &win);

#if MPI_VERSION >= 3
        if (type == WIN_DYNAMIC) {
            disp = disp_remote;
        }
#endif
        if(size > LARGE_MESSAGE_SIZE) {
            loop = LOOP_LARGE;
            skip = SKIP_LARGE;
        }

        if(rank == 0) {
            for (i = 0; i < skip + loop; i++) {
                if (i == skip) {
                    t_start = MPI_Wtime ();
                }
                MPI_CHECK(MPI_Win_lock(MPI_LOCK_SHARED, 1, 0, win));
                MPI_CHECK(MPI_Accumulate(sbuf, size, MPI_CHAR, 1, disp, size, MPI_CHAR, MPI_SUM, win));
                MPI_CHECK(MPI_Win_unlock(1, win));
            }
            t_end = MPI_Wtime ();
        }                

        MPI_CHECK(MPI_Barrier(MPI_COMM_WORLD));

        print_latency(rank, size);

        free_memory (sbuf, rbuf, win, rank);
    }
}
Example #21
0
void
m2m_destroy(m2m* me /* own. null */) {
    if (!me) return;
    ENSURE(me->base.type == &m2m_t)
    hashtable_destroy(me->employee_by_name);
    m2m_foreach_employee(
						 me,
						 (employee_fun)record_destructor,
						 me);
    array_table_cleanup(&me->employee);
    hashtable_destroy(me->department_by_title);
    m2m_foreach_department(
						   me,
						   (department_fun)record_destructor,
						   me);
    array_table_cleanup(&me->department);
    m2m_foreach_company(
						me,
						(company_fun)record_destructor,
						me);
    array_table_cleanup(&me->company);
    free_memory(me, sizeof(m2m));
}
Example #22
0
/*
 * Update File Attributes in the catalog with data
 *  sent by the Storage daemon.
 */
void catalog_update(JCR *jcr, BSOCK *bs)
{
   if (!jcr->res.pool->catalog_files) {
      return;                         /* user disabled cataloging */
   }
   if (jcr->is_job_canceled()) {
      goto bail_out;
   }
   if (!jcr->db) {
      POOLMEM *omsg = get_memory(bs->msglen+1);
      pm_strcpy(omsg, bs->msg);
      bs->fsend(_("1994 Invalid Catalog Update: %s"), omsg);
      Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
      free_memory(omsg);
      goto bail_out;
   }
   update_attribute(jcr, bs->msg, bs->msglen);

bail_out:
   if (jcr->is_job_canceled()) {
      cancel_storage_daemon_job(jcr);
   }
}
Example #23
0
static void *main_thread(void *p)
{
   if (GTK_TOGGLE_BUTTON(dynam)->active == 1) dynacore = 1;
   else if (GTK_TOGGLE_BUTTON(pure_interp)->active == 1) dynacore = 2;
   else dynacore = 0;
   
   SDL_Init(SDL_INIT_VIDEO);
   SDL_SetVideoMode(10, 10, 16, 0);
   SDL_SetEventFilter(filter);
   SDL_ShowCursor(0);
   SDL_EnableKeyRepeat(0, 0);
   
   init_memory();
   plugin_load_plugins(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_gfx)->entry)),
		       gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_audio)->entry)),
		       gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_input)->entry)),
		       gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(combo_RSP)->entry)));
   romOpen_gfx();
   romOpen_audio();
   romOpen_input();
   go();
   romClosed_RSP();
   romClosed_input();
   romClosed_audio();
   romClosed_gfx();
   closeDLL_RSP();
   closeDLL_input();
   closeDLL_audio();
   closeDLL_gfx();
   free(rom);
   rom = NULL;
   free(ROM_HEADER);
   ROM_HEADER = NULL;
   free_memory();
   file_selection_launched = 0;
   return 0;
}
Example #24
0
void mux_channel_list_remove(MuxChannelList *list, MuxPipe pipe)
{
    MuxChannelNode *current_node = list->head;
    MuxChannelNode *previous_node = NULL;

    /* Search list for our in_pin to remove it */
    while (NULL != current_node) {
	int current_channel = current_node->channel;

	if (current_channel == pipe.channel) {
	    mux_input_list_remove(&current_node->inputs, pipe.in_pin);

	    if (NULL == current_node->inputs.head) {
		/* No more inputs, need to remove this channel */
		if (NULL != previous_node) {
		    previous_node->next = current_node->next;
		}

		/* Adjust the head and tail if necessary */
		if (current_node == list->head) {
		    list->head = list->head->next;
		}

		if (current_node == list->tail) {
		    list->tail = previous_node;
		}

		free_memory(current_node);
	    }

	    return;
	}

	previous_node = current_node;
	current_node = current_node->next;
    }
}
Example #25
0
/* Here we load one block of a snapshot file. It can be distributed
 * onto several files (for files>1).  It then gets output as an array file.
 */
int main(int argc, char **argv)
{
  char basename[200];
  int  type, files;
  int block_nr;
  int iDim;
  int i;
  int j;
  
  if(argc != 3 && argc != 4) 
    {
      fprintf(stderr,
	      "usage: snap2arr block snapbase [N_files]\n");
      exit(-1);
    }

  block_nr = atoi(argv[1]);
  strcpy(basename, argv[2]);
  
  if(argc == 4 ) 
    {
      files = atoi(argv[3]);	/* # of files per snapshot */
    }
  else 
    files = 1;

  iDim = load_snapshot(basename, block_nr, files);

  for(i=1; i<=NumPart; i++) {
      for(j = 0; j < iDim; j++) {
	  printf("%g\n", P[i].Pos[j]);
	  }
      }
  free_memory(); 

  return 0;
}
Example #26
0
void Func_ResetROM()
{
	if(hasLoadedROM)
	{
		cpu_deinit();
		romClosed_RSP();
		romClosed_input();
		romClosed_audio();
		romClosed_gfx();
		free_memory();
		
		init_memory();
		romOpen_gfx();
		romOpen_audio();
		romOpen_input();
		cpu_init();
		menu::MessageBox::getInstance().setMessage("Game restarted");
		Func_SetPlayGame();
	}
	else	
	{
		menu::MessageBox::getInstance().setMessage("Please load a ROM first");
	}
}
Example #27
0
IDL_LONG idl_dsmooth (int      argc,
                      void *   argv[])
{
	IDL_LONG nx,ny;
	float *image, *smooth, sigma;
	
	IDL_LONG i;
	IDL_LONG retval=1;

	/* 0. allocate pointers from IDL */
	i=0;
	image=((float *)argv[i]); i++;
	nx=*((int *)argv[i]); i++;
	ny=*((int *)argv[i]); i++;
  sigma=*((float *)argv[i]); i++;
  smooth=((float *)argv[i]); i++;
	
	/* 1. run the fitting routine */
	retval=(IDL_LONG) dsmooth(image, nx, ny, sigma, smooth);
	
	/* 2. free memory and leave */
	free_memory();
	return retval;
}
/* This function is called periodically by status_run(). It updates the device_state_t
 * data, which is accessed by the READ command in object device
 */
void device_state_update() {
	struct timeval now;

	if (!first_time) {
		first_time = 1;
		ad_init(0);
		ad_init(1);
	}

	gettimeofday(&now, NULL);
	device_state.cur_time = now.tv_sec;
	device_state.ps_voltage[0] = 5000;
	device_state.ps_current[0] = 500;

	device_state.ps_current[1] = 500;
	device_state.ps_voltage[1] = ad_read(0);

	device_state.ps_current[2] = 500;
	device_state.ps_voltage[2] = ad_read(1);

	device_state.error_code = 0;
	device_state.memory_free = free_memory();
	device_state.state_code = 0;
}
Example #29
0
File: bsys.c Project: pstray/bareos
/*
 * Implement vsnprintf()
 */
int bvsnprintf(char *str, int32_t size, const char  *format, va_list ap)
{
#ifdef HAVE_VSNPRINTF
   int len;
   len = vsnprintf(str, size, format, ap);
   str[size-1] = 0;
   return len;

#else

   int len, buflen;
   char *buf;
   buflen = size > BIG_BUF ? size : BIG_BUF;
   buf = get_memory(buflen);
   len = vsprintf(buf, format, ap);
   if (len >= buflen) {
      Emsg0(M_ABORT, 0, _("Buffer overflow.\n"));
   }
   memcpy(str, buf, len);
   str[len] = 0;                /* len excludes the null */
   free_memory(buf);
   return len;
#endif
}
Example #30
0
/**
 * Convert a wide-character string to a new character string
 * @param source Pointer to the wide-chars string to be converted  
 * @param length The number of wide-chars in the source string
 * @param code_page The code page used to perform the conversion
 * @return Pointer to the buffer to receive the translated string or
 *         NULL upon failure. This buffer must be released once it is 
 *         not needed anymore
 */
char *
wide_char_to_bytes (wchar_t * source, Uint32 length, Uint32 code_page)
{
  Sint32 size;
  char *dest;
  if (source == NULL)
    {
      return NULL;
    }
  if (length == 0)
    {
      length = wcslen (source) + 1;
    }
  size = WideCharToMultiByte (code_page, 0, source, length,
                              NULL, 0, NULL, NULL);
  if (size == 0)
    {
      LOG_ERR ("WideCharToMultiByte() failed!");
      return NULL;
    }
  dest = memory_allocation (size);
  if (dest == NULL)
    {
      LOG_ERR ("not enough memory to allocate %i bytes", size);
    }
  size = WideCharToMultiByte (code_page, 0, source, length,
                              dest, size, NULL, NULL);
  if (size == 0)
    {
      LOG_ERR ("WideCharToMultiByte() failed!");
      free_memory (dest);
      return NULL;
    }
  dest[size] = 0;
  return dest;
}