Browse Source

use only TMALLOC and TREALLOC for memory allocation

pre-master-46
Holger Vogt 6 years ago
parent
commit
966b69090d
  1. 2
      src/frontend/com_sysinfo.c
  2. 6
      src/include/ngspice/dstring.h
  3. 3
      src/misc/dstring.c

2
src/frontend/com_sysinfo.c

@ -924,7 +924,7 @@ static void get_physical_processor_count(void)
/* Allocate buffer to get the info */ /* Allocate buffer to get the info */
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX * const buf = SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX * const buf =
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) malloc(n_byte_buf);
(SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)TMALLOC(char, n_byte_buf);
if (buf == (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) NULL) { if (buf == (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *) NULL) {
fprintf(cp_err, fprintf(cp_err,
"Unable to allocate a buffer of %lu bytes " "Unable to allocate a buffer of %lu bytes "

6
src/include/ngspice/dstring.h

@ -8,6 +8,8 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "ngspice/memory.h"
/* Error codes */ /* Error codes */
#define DS_E_OK 0 #define DS_E_OK 0
@ -192,7 +194,7 @@ inline char *ds_free_move(DSTRING *p_ds, unsigned int opt)
if (opt & DS_FREE_MOVE_OPT_FORCE_ALLOC) { if (opt & DS_FREE_MOVE_OPT_FORCE_ALLOC) {
/* Allocate to minimum size */ /* Allocate to minimum size */
size_t n_byte_alloc = p_ds->length + 1; size_t n_byte_alloc = p_ds->length + 1;
char * const p_ret = (char *) malloc(n_byte_alloc);
char * const p_ret = TMALLOC(char, n_byte_alloc);
if (p_ret == (char *) NULL) { if (p_ret == (char *) NULL) {
return (char *) NULL; return (char *) NULL;
} }
@ -204,7 +206,7 @@ inline char *ds_free_move(DSTRING *p_ds, unsigned int opt)
if (opt & DS_FREE_MOVE_OPT_COMPACT) { if (opt & DS_FREE_MOVE_OPT_COMPACT) {
/* Allocate to minimum size */ /* Allocate to minimum size */
size_t n_byte_alloc = p_ds->length + 1; size_t n_byte_alloc = p_ds->length + 1;
char * const p_ret = (char *) realloc(p_buf_active, n_byte_alloc);
char * const p_ret = TREALLOC(char, p_buf_active, n_byte_alloc);
if (p_ret == (char *) NULL) { if (p_ret == (char *) NULL) {
/* Realloc to smaller size somehow failed! */ /* Realloc to smaller size somehow failed! */
return (char *) NULL; return (char *) NULL;

3
src/misc/dstring.c

@ -4,7 +4,6 @@ DESCRIPTION:This file contains the routines for manipulating dynamic strings.
----------------------------------------------------------------- */ ----------------------------------------------------------------- */
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -347,7 +346,7 @@ int ds_compact(DSTRING *p_ds)
/* Else realloc the heap buffer */ /* Else realloc the heap buffer */
{ {
void *p = realloc(p_ds->p_buf, n_byte_alloc_min);
void *p = TREALLOC(char, p_ds->p_buf, n_byte_alloc_min);
if (p == NULL) { if (p == NULL) {
return DS_E_NO_MEMORY; return DS_E_NO_MEMORY;
} }

Loading…
Cancel
Save