]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gprofng: use xmalloc/xrealloc/xcalloc/xstrdup/xstrndup from libiberty
authorAndreas Schwab <schwab@suse.de>
Mon, 14 Oct 2024 12:54:34 +0000 (14:54 +0200)
committerAndreas Schwab <schwab@suse.de>
Wed, 16 Oct 2024 13:34:07 +0000 (15:34 +0200)
PR gprofng/32241
* src/Makefile.am (CSOURCES): Remove dbe_memmgr.c
* src/Makefile.in: Regenerate.
* src/dbe_memmgr.c: Remove.
* src/gprofng.cc (main): Call xmalloc_set_program_name.
* src/gp-archive.cc (main): Likewise.
* src/gp-collect-app.cc (main): Likewise.
* src/gp-display-src.cc (main): Likewise.
* src/gp-display-text.cc (main): Likewise.
* src/Application.cc: Use xmalloc, xrealloc, xcalloc, xstrdup,
xstrndup instead of malloc, realloc, calloc, strdup, strndup.
* src/BaseMetric.cc: Likewise.
* src/CallStack.cc: Likewise.
* src/ClassFile.cc: Likewise.
* src/Data_window.cc: Likewise.
* src/Dbe.cc: Likewise.
* src/DbeJarFile.cc: Likewise.
* src/DbeSession.cc: Likewise.
* src/DbeView.cc: Likewise.
* src/DerivedMetrics.cc: Likewise.
* src/DwarfLib.cc: Likewise.
* src/Elf.cc: Likewise.
* src/Emsg.cc: Likewise.
* src/Experiment.cc: Likewise.
* src/Function.cc: Likewise.
* src/Module.cc: Likewise.
* src/Print.cc: Likewise.
* src/QLParser.yy: Likewise.
* src/SAXParserFactory.cc: Likewise.
* src/Settings.cc: Likewise.
* src/SourceFile.cc: Likewise.
* src/StringBuilder.cc: Likewise.
* src/StringMap.h: Likewise.
* src/Table.cc: Likewise.
* src/checks.cc: Likewise.
* src/collctrl.cc: Likewise.
* src/comp_com.c: Likewise.
* src/count.cc: Likewise.
* src/envsets.cc: Likewise.
* src/gp-archive.cc: Likewise.
* src/gp-display-src.cc: Likewise.
* src/gp-display-text.cc: Likewise.
* src/gprofng.cc: Likewise.
* src/ipc.cc: Likewise.
* src/ipcio.cc: Likewise.
* src/vec.h: Likewise.
* src/util.cc: Likewise.
(get_prog_name): Remove.
* src/util.h: Likewise.
* src/dbe_hwc.h (malloc, realloc, calloc, strdup): Define.

43 files changed:
gprofng/src/Application.cc
gprofng/src/BaseMetric.cc
gprofng/src/CallStack.cc
gprofng/src/ClassFile.cc
gprofng/src/Data_window.cc
gprofng/src/Dbe.cc
gprofng/src/DbeJarFile.cc
gprofng/src/DbeSession.cc
gprofng/src/DbeView.cc
gprofng/src/DerivedMetrics.cc
gprofng/src/DwarfLib.cc
gprofng/src/Elf.cc
gprofng/src/Emsg.cc
gprofng/src/Experiment.cc
gprofng/src/Function.cc
gprofng/src/Makefile.am
gprofng/src/Makefile.in
gprofng/src/Module.cc
gprofng/src/Print.cc
gprofng/src/QLParser.yy
gprofng/src/SAXParserFactory.cc
gprofng/src/Settings.cc
gprofng/src/SourceFile.cc
gprofng/src/StringBuilder.cc
gprofng/src/StringMap.h
gprofng/src/Table.cc
gprofng/src/checks.cc
gprofng/src/collctrl.cc
gprofng/src/comp_com.c
gprofng/src/count.cc
gprofng/src/dbe_hwc.h
gprofng/src/dbe_memmgr.c [deleted file]
gprofng/src/envsets.cc
gprofng/src/gp-archive.cc
gprofng/src/gp-collect-app.cc
gprofng/src/gp-display-src.cc
gprofng/src/gp-display-text.cc
gprofng/src/gprofng.cc
gprofng/src/ipc.cc
gprofng/src/ipcio.cc
gprofng/src/util.cc
gprofng/src/util.h
gprofng/src/vec.h

index 98caebab4d06b605e57c39259e116e4c00c27f53..ee461b3109b8ce6ed8fcff7f7d9eb9d074c45794 100644 (file)
@@ -112,7 +112,7 @@ Application::get_realpath (const char *_name)
              path = s + 1;
            }
     }
-  return strdup (_name);
+  return xstrdup (_name);
 }
 
 // Set the directory where all binaries are found
index ae0ee32adf8e6e95ac5a0c13446711257440ade7..b7475e2ecd1fdc6569802e55b3dbd8ec2846286d 100644 (file)
@@ -238,7 +238,7 @@ BaseMetric::BaseMetric (const BaseMetric& m)
     default_visbits[ii] = m.default_visbits[ii];
   if (m.cond_spec)
     {
-      cond_spec = strdup (m.cond_spec);
+      cond_spec = xstrdup (m.cond_spec);
       cond = m.cond->copy ();
     }
   else
@@ -248,7 +248,7 @@ BaseMetric::BaseMetric (const BaseMetric& m)
     }
   if (m.val_spec)
     {
-      val_spec = strdup (m.val_spec);
+      val_spec = xstrdup (m.val_spec);
       val = m.val->copy ();
     }
   else
@@ -258,7 +258,7 @@ BaseMetric::BaseMetric (const BaseMetric& m)
     }
   if (m.expr_spec)
     {
-      expr_spec = strdup (m.expr_spec);
+      expr_spec = xstrdup (m.expr_spec);
       expr = m.expr->copy ();
     }
   else
index 5bfafb7b2ca5ad9ea2cb15b3ce5ce244703c673d..15594a286c04210abb9708868a7150a67de9d15a 100644 (file)
@@ -89,7 +89,7 @@ Descendants::insert (int ind, CallStackNode* item)
   if (old_cnt + 1 >= limit)
     {
       int new_limit = (limit == 0) ? DELTA : limit * 2;
-      CallStackNode **new_data = (CallStackNode **) malloc (new_limit * sizeof (CallStackNode *));
+      CallStackNode **new_data = (CallStackNode **) xmalloc (new_limit * sizeof (CallStackNode *));
       for (int i = 0; i < ind; i++)
        new_data[i] = old_data[i];
       new_data[ind] = item;
@@ -204,12 +204,12 @@ CallStackP::new_Node (CallStackNode *anc, Histable *pcval)
       nchunks++;
 
       // Reallocate Node chunk array
-      chunks = (CallStackNode **) malloc (nchunks * sizeof (CallStackNode *));
+      chunks = (CallStackNode **) xmalloc (nchunks * sizeof (CallStackNode *));
       for (int i = 0; i < nchunks - 1; i++)
        chunks[i] = old_chunks[i];
       free (old_chunks);
       // Allocate new chunk for nodes.
-      chunks[nchunks - 1] = (CallStackNode *) malloc (CHUNKSZ * sizeof (CallStackNode));
+      chunks[nchunks - 1] = (CallStackNode *) xmalloc (CHUNKSZ * sizeof (CallStackNode));
     }
   nodes++;
   CallStackNode *node = get_node (nodes - 1);
index 37dd0ff2f718a029193b459233050b2b0944ef24..51bb0c298b1ed3e9fdeae226e5b8bbc382aaa79a 100644 (file)
@@ -957,7 +957,7 @@ BinaryConstantPool::getString (int index)
       return NULL;
     }
   u2 len = input->readUnsignedShort ();
-  strings[index] = (char *) malloc (len + 1);
+  strings[index] = (char *) xmalloc (len + 1);
   input->copy_bytes (strings[index], len);
   return strings[index];
 }
@@ -1014,7 +1014,7 @@ ClassFile::openFile (const char *fname)
       return;
     }
   cf_bufsz = stat_buf.st_size;
-  cf_buf = (unsigned char *) malloc (cf_bufsz);
+  cf_buf = (unsigned char *) xmalloc (cf_bufsz);
   if (cf_bufsz != read_from_file (fd, cf_buf, cf_bufsz))
     {
       free (cf_buf);
@@ -1409,7 +1409,7 @@ ClassFile::readFile ()
       class_filename = dbe_strdup (bcpool->getString (classNameInd));
       if (class_filename)
        {
-         class_name = strdup (class_filename);
+         class_name = xstrdup (class_filename);
          convertName (class_name);
        }
 
@@ -1527,7 +1527,7 @@ ClassFile::readFile ()
   if (class_filename)
     {
       if (strcmp (class_filename, get_name ()) != 0)
-       set_name (strdup (class_filename));
+       set_name (xstrdup (class_filename));
       if (source_name)
        {
          char *bname = strrchr (class_filename, '/');
@@ -1535,13 +1535,13 @@ ClassFile::readFile ()
            fnm = dbe_sprintf (NTXT ("%.*s/%s"), (int) (bname - class_filename),
                               class_filename, source_name);
          else
-           fnm = strdup (source_name);
+           fnm = xstrdup (source_name);
        }
       else
        fnm = get_java_file_name (class_filename, false);
     }
   else if (source_name)
-    fnm = strdup (source_name);
+    fnm = xstrdup (source_name);
   if (fnm)
     {
       set_file_name (fnm);
@@ -1631,7 +1631,7 @@ ClassFile::get_java_file_name (char *clname, bool classSuffix)
       if (tmp)
        len = tmp - clname;
     }
-  char *clpath = (char *) malloc (len + 10);
+  char *clpath = (char *) xmalloc (len + 10);
   for (size_t i = 0; i < len; i++)
     clpath[i] = (clname[i] == '.') ? '/' : clname[i];
   snprintf (clpath + len, 10, classSuffix ? NTXT (".class") : NTXT (".java"));
index da142f033f86543b6f9bfa133b8ad1f14cf5a8e1..be08559c162d830efa254bb13b5446a35d7f7bb1 100644 (file)
@@ -149,7 +149,7 @@ Data_window::bind (Span *span, int64_t minSize)
            { // Need to realloc 'base'
              free (base);
              basesize = wsize;
-             base = (void *) malloc (basesize);
+             base = (void *) xmalloc (basesize);
              Dprintf (DEBUG_DATA_WINDOW,
                       NTXT ("Data_window:bind:%d realloc basesize=%llx woffset=%lld \n"),
                       (int) __LINE__, (long long) basesize, (long long) woffset);
@@ -188,7 +188,7 @@ Data_window::get_data (int64_t offset, int64_t size, void *datap)
     return NULL;
   if (datap == NULL && !mmap_on_file)
     // Can be remmaped or reallocated. Need to make a copy
-    datap = (void *) malloc (size);
+    datap = (void *) xmalloc (size);
   if (datap)
     {
       memcpy (datap, buf, (size_t) size);
index 09b7f94eaa8e3fbf10a8fd38764bc23e13df76a4..c46313ab488d20e631cf20c234521bd8ca5958d3 100644 (file)
@@ -353,7 +353,7 @@ dbeReadFile (const char *pathname)
 {
   Vector<char*> *result = new Vector<char*>(2);
   int limit = 1024 * 1024; // Temporary limit: 1 MB
-  char * contents = (char *) malloc (limit);
+  char * contents = (char *) xmalloc (limit);
   StringBuilder sb;
   if (NULL == contents)
     {
@@ -4960,7 +4960,7 @@ dbeGetFuncList (int dbevindex, int type, int subtype)
              //        it needs to be
              // first, scan all the lines, to get the maximum line number
              bufsz = 1024;
-             buf = (char *) malloc (bufsz);
+             buf = (char *) xmalloc (bufsz);
              int max_lineno = 0;
              int hidx;
              Hist_data::HistItem *hitem;
@@ -5047,7 +5047,7 @@ dbeGetFuncList (int dbevindex, int type, int subtype)
                              // Reallocate the buffer
                              size_t curlen = d - buf;
                              bufsz += 1024;
-                             char *buf_new = (char *) malloc (bufsz);
+                             char *buf_new = (char *) xmalloc (bufsz);
                              strncpy (buf_new, buf, curlen);
                              buf_new[curlen] = '\0';
                              free (buf);
@@ -5243,7 +5243,7 @@ dbeGetFuncListV2 (int dbevindex, int mtype, Obj sel_obj, int type, int subtype)
            //  it needs to be
            // first, scan all the lines, to get the maximum line number
            bufsz = 1024;
-           buf = (char *) malloc (bufsz);
+           buf = (char *) xmalloc (bufsz);
            int max_lineno = 0;
            int hidx;
            Hist_data::HistItem *hitem;
@@ -5334,7 +5334,7 @@ dbeGetFuncListV2 (int dbevindex, int mtype, Obj sel_obj, int type, int subtype)
                            // Reallocate the buffer
                            size_t curlen = d - buf;
                            bufsz += 1024;
-                           char *buf_new = (char *) malloc (bufsz);
+                           char *buf_new = (char *) xmalloc (bufsz);
                            strncpy (buf_new, buf, curlen);
                            buf_new[curlen] = '\0';
                            free (buf);
@@ -6089,7 +6089,7 @@ dbeGetStatisList (int dbevindex)
     return NULL;
 
   // Get statistics data
-  data = (Stats_data **) malloc ((size + 1) * sizeof (Stats_data *));
+  data = (Stats_data **) xmalloc ((size + 1) * sizeof (Stats_data *));
   data[0] = new Stats_data ();
   for (index = 1; index <= size; index++)
     {
@@ -7006,8 +7006,8 @@ dbeGetSummary (int dbevindex, Vector<Obj> *sel_objs, int type, int subtype)
       if (map != NULL)
        {
          int nmetrics = mvec->size ();
-         double *evalues = (double *) malloc (nmetrics * sizeof (double));
-         double *ivalues = (double *) malloc (nmetrics * sizeof (double));
+         double *evalues = (double *) xmalloc (nmetrics * sizeof (double));
+         double *ivalues = (double *) xmalloc (nmetrics * sizeof (double));
          for (index2 = 0; index2 < nmetrics; index2++)
            {
              evalues[index2] = excl_list->fetch (index2);
@@ -7090,8 +7090,8 @@ dbeGetHwcSets (int /*dbevindex*/, bool forKernel)
   Vector<char*> *name = new Vector<char*>(1); // Internal name
   if (NULL != defctrs)
     {
-      i18n->store (0, strdup (defctrs));
-      name->store (0, strdup (NTXT ("default")));
+      i18n->store (0, xstrdup (defctrs));
+      name->store (0, xstrdup (NTXT ("default")));
     }
   list->store (0, i18n);
   list->store (1, name);
@@ -8692,8 +8692,8 @@ dbeGetDataDescriptorsV2 (int exp_id)
       int data_id = dataDscr->getId ();
       int aux_prop_id = (data_id == DATA_HWC) ? PROP_HWCTAG : PROP_NONE;
       dataId->append (data_id);
-      dataName->append (strdup (dataDscr->getName ()));
-      dataUName->append (strdup (dataDscr->getUName ()));
+      dataName->append (xstrdup (dataDscr->getName ()));
+      dataUName->append (xstrdup (dataDscr->getUName ()));
       auxProp->append (aux_prop_id);
     }
   delete ddscr;
@@ -9921,8 +9921,8 @@ dbeGetLineInfo (Obj pc)
   if (dbeline != NULL)
     snprintf (lineno, sizeof (lineno), NTXT ("%d"), dbeline->lineno);
   Vector<char*> *res = new Vector<char*>(2);
-  res->store (0, strdup (fname));
-  res->store (1, strdup (lineno));
+  res->store (0, xstrdup (fname));
+  res->store (1, xstrdup (lineno));
   return res;
 }
 
index fe3427f0b545df7ba88bfed8c04ccf83f152e01d..b2bb355878585ada8865167278c5bfad3154427c 100644 (file)
@@ -123,7 +123,7 @@ template<> void Vector<ZipEntry *>::dump (const char *msg)
 
 DbeJarFile::DbeJarFile (const char *jarName)
 {
-  name = strdup (jarName);
+  name = xstrdup (jarName);
   fnames = NULL;
   dwin = new Data_window (name);
   get_entries ();
@@ -211,7 +211,7 @@ DbeJarFile::get_entries ()
       char *nm = (char *) dwin->bind (offset + 46, name_len);
       if (nm)
        {
-         ze->name = (char *) malloc (name_len + 1);
+         ze->name = (char *) xmalloc (name_len + 1);
          strncpy (ze->name, nm, name_len);
          ze->name[name_len] = 0;
        }
@@ -320,7 +320,7 @@ DbeJarFile::copy (char *toFileNname, int fromEntryNum)
   strm.avail_in = ze->csize;
   strm.next_in = b;
   int retval = ze->size;
-  unsigned char *buf = (unsigned char *) malloc (ze->size);
+  unsigned char *buf = (unsigned char *) xmalloc (ze->size);
   for (;;)
     {
       strm.next_out = buf;
index 3649357bc797861df372e0dd9e4c0e6ea6542fc7..2a8a6f2c0390ad93207d903752f29d5b94415daa 100644 (file)
@@ -1245,7 +1245,7 @@ DbeSession::open_experiment (Experiment *exp, char *path)
     {
       if (t_exp_list[j] == NULL) continue;
       Experiment *dexp = t_exp_list[j];
-      exp_ctx *new_ctx = (exp_ctx*) malloc (sizeof (exp_ctx));
+      exp_ctx *new_ctx = (exp_ctx*) xmalloc (sizeof (exp_ctx));
       new_ctx->path = NULL;
       new_ctx->exp = dexp;
       new_ctx->ds = this;
index 6b0c3a40cb3407b1fb226852953272db5f265950..872ebcd7a348d582c1aec5b4aaa0342bdd8edf92 100644 (file)
@@ -552,7 +552,7 @@ DbeView::get_metric_list (MetricType mtype)
 
       // set the defaults
       if (settings->str_dmetrics == NULL)
-       settings->str_dmetrics = strdup (Command::DEFAULT_METRICS);
+       settings->str_dmetrics = xstrdup (Command::DEFAULT_METRICS);
       char *status = setMetrics (settings->str_dmetrics, true);
       if (status != NULL)
        {
@@ -1122,7 +1122,7 @@ DbeView::setSort (char * sort_list, MetricType mtype, bool fromRcFile)
   if ((sort_list == NULL) || (strcmp (sort_list, Command::DEFAULT_CMD) == 0))
     {
       if (settings->str_dsort == NULL)
-       settings->str_dsort = strdup (Command::DEFAULT_METRICS);
+       settings->str_dsort = xstrdup (Command::DEFAULT_METRICS);
       sort_list = settings->get_default_sort ();
     }
   mlist = get_metric_list (mtype);
index ee14ea01542c09cb2649a224b763625d8c39700a..14026d6b76b60c0b918f1b64bb33e2c62712c410 100644 (file)
@@ -119,7 +119,7 @@ DerivedMetrics::construct_map (Vector<Metric*> *mitems, BaseMetric::SubType st,
   int nmetrics = mitems->size ();
 
   // allocate arrays for the mapping between derived metrics and requested values
-  int *map = (int *) malloc (ndm * sizeof (int));
+  int *map = (int *) xmalloc (ndm * sizeof (int));
 
   // map derived metrics to requested metrics    // EUGENE explain this more clearly
   //   0  means not mapped
@@ -194,7 +194,7 @@ DerivedMetrics::get_dependencies (definition *def)
   int n = items->size ();
 
   // zero out a vector representing definitions
-  int *vec = (int *) malloc (n * sizeof (int));
+  int *vec = (int *) xmalloc (n * sizeof (int));
   for (int i = 0; i < n; i++)
     vec[i] = 0;
   fill_dependencies (def, vec);
index a150c76cdd5c1d8f0e637aecd41387a13452e026..3872cc2de469dc9948db24a44cb81a192e7ac478 100644 (file)
@@ -1523,7 +1523,7 @@ DwrLineRegs::read_file_names_dwarf5 ()
           (long long) debug_lineSec->offset, efmt_cnt);
   if (efmt_cnt == 0)
     return NULL;
-  t_entry_fmt *efmt = (t_entry_fmt *) malloc (sizeof (t_entry_fmt) * efmt_cnt);
+  t_entry_fmt *efmt = (t_entry_fmt *) xmalloc (sizeof (t_entry_fmt) * efmt_cnt);
   for (int i = 0; i < efmt_cnt; i++)
     {
       efmt[i].type_code = debug_lineSec->GetULEB128 ();
@@ -2350,8 +2350,8 @@ DwrCU::map_dwarf_lines (Module *mod)
   if (isGNU && (inlinedSubrCnt > 0))
     {
       Function *func = NULL;
-      mod->inlinedSubr = (InlinedSubr *) malloc (inlinedSubrCnt
-                                                * sizeof (InlinedSubr));
+      mod->inlinedSubr = (InlinedSubr *) xmalloc (inlinedSubrCnt
+                                                 * sizeof (InlinedSubr));
       for (long i = 0; i < inlinedSubrCnt; i++)
        {
          DwrInlinedSubr *inlinedSubr = dwrInlinedSubrs->get (i);
index 45f889316424db540212f2e815e9c3fcd8267155..7c715616ac76f84a80c49eb37280b041b35571bd 100644 (file)
@@ -405,7 +405,7 @@ Elf::elf_getdata (unsigned int sec)
 {
   if (data == NULL)
     {
-      data = (Elf_Data **) malloc (ehdrp->e_shnum * sizeof (Elf_Data *));
+      data = (Elf_Data **) xmalloc (ehdrp->e_shnum * sizeof (Elf_Data *));
       for (int i = 0; i < (int) ehdrp->e_shnum; i++)
        data[i] = NULL;
     }
@@ -744,7 +744,7 @@ Elf::get_bfd_symbols()
        bfd_symcnt = bfd_get_symtab_upper_bound (abfd);
       if (bfd_symcnt > 0)
        {
-         bfd_sym = (asymbol **) malloc (bfd_symcnt);
+         bfd_sym = (asymbol **) xmalloc (bfd_symcnt);
          bfd_symcnt = bfd_canonicalize_symtab (abfd, bfd_sym);
          if (bfd_symcnt < 0)
            {
@@ -761,7 +761,7 @@ Elf::get_bfd_symbols()
       bfd_dynsymcnt = bfd_get_dynamic_symtab_upper_bound (abfd);
       if (bfd_dynsymcnt > 0)
        {
-         bfd_dynsym = (asymbol **) malloc (bfd_dynsymcnt);
+         bfd_dynsym = (asymbol **) xmalloc (bfd_dynsymcnt);
          bfd_dynsymcnt = bfd_canonicalize_dynamic_symtab (abfd, bfd_dynsym);
          if (bfd_dynsymcnt < 0)
            {
index 01620590b9188ad5829e8b933311f1b044f92115..eada9aec418e72f2723bcb86ca576eee6593d80a 100644 (file)
@@ -39,7 +39,7 @@ Emsg::Emsg (Cmsg_warn w, const char *i18n_text)
   warn = w;
   flavor = 0;
   par = NULL;
-  text = strdup (i18n_text);
+  text = xstrdup (i18n_text);
   next = NULL;
 }
 
@@ -436,7 +436,7 @@ Emsgqueue::Emsgqueue (char *_qname)
 {
   first = NULL;
   last = NULL;
-  qname = strdup (_qname);
+  qname = xstrdup (_qname);
 }
 
 Emsgqueue::~Emsgqueue ()
@@ -584,7 +584,7 @@ DbeMessages::append_msg (Cmsg_warn w, const char *fmt, ...)
   else
     {
       va_start (vp, fmt);
-      char *buf = (char *) malloc (buf_size);
+      char *buf = (char *) xmalloc (buf_size);
       vsnprintf (buf, buf_size, fmt, vp);
       va_end (vp);
       msg = new Emsg (w, buf);
index 3e1e1a7d39ef7fce8925e681637da1522ded19db..3c63f9f018fb11e3816c920be52ebf4a4750a331 100644 (file)
@@ -252,9 +252,7 @@ Experiment::ExperimentFile::fgets ()
   if (bufsz == 0)
     {
       bufsz = 1024;
-      buffer = (char *) malloc (bufsz);
-      if (buffer == NULL)
-       return NULL;
+      buffer = (char *) xmalloc (bufsz);
       buffer[bufsz - 1] = (char) 1; // sentinel
     }
   char *res = ::fgets (buffer, bufsz, fh);
@@ -263,9 +261,7 @@ Experiment::ExperimentFile::fgets ()
   while (buffer[bufsz - 1] == (char) 0)
     {
       int newsz = bufsz + 1024;
-      char *newbuf = (char *) malloc (newsz);
-      if (newbuf == NULL)
-       return NULL;
+      char *newbuf = (char *) xmalloc (newsz);
       memcpy (newbuf, buffer, bufsz);
       free (buffer);
       buffer = newbuf;
@@ -451,19 +447,19 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
       if (str != NULL)
        {
          found = 1;
-         exp->coll_params.start_delay = strdup (str);
+         exp->coll_params.start_delay = xstrdup (str);
        }
       str = attrs->getValue (SP_JCMD_TERMINATE);
       if (str != NULL)
        {
          found = 1;
-         exp->coll_params.terminate = strdup (str);
+         exp->coll_params.terminate = xstrdup (str);
        }
       str = attrs->getValue (SP_JCMD_PAUSE_SIG);
       if (str != NULL)
        {
          found = 1;
-         exp->coll_params.pause_sig = strdup (str);
+         exp->coll_params.pause_sig = xstrdup (str);
        }
       str = attrs->getValue (SP_JCMD_SAMPLE_PERIOD);
       if (str != NULL)
@@ -491,7 +487,7 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
       if (str != NULL)
        {
          found = 1;
-         exp->coll_params.linetrace = strdup (str);
+         exp->coll_params.linetrace = xstrdup (str);
        }
 
       str = attrs->getValue (SP_JCMD_COLLENV);
@@ -524,11 +520,11 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
       pushElem (EL_SYSTEM);
       const char *str = attrs->getValue (NTXT ("hostname"));
       if (str != NULL)
-       exp->hostname = strdup (str);
+       exp->hostname = xstrdup (str);
       str = attrs->getValue (NTXT ("os"));
       if (str != NULL)
        {
-         exp->os_version = strdup (str);
+         exp->os_version = xstrdup (str);
          /* For Linux experiments expect sparse thread ID's */
          if (strncmp (str, NTXT ("SunOS"), 5) != 0)
            exp->sparse_threads = true;
@@ -547,7 +543,7 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
            exp->platform = Sparc;
          exp->need_swap_endian = (DbeSession::platform == Sparc) ?
                  (exp->platform != Sparc) : (exp->platform == Sparc);
-         exp->architecture = strdup (str);
+         exp->architecture = xstrdup (str);
        }
       str = attrs->getValue (NTXT ("pagesz"));
       if (str != NULL)
@@ -624,7 +620,7 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
        exp->sid = atoi (str);
       str = attrs->getValue (NTXT ("cwd"));
       if (str != NULL)
-       exp->ucwd = strdup (str);
+       exp->ucwd = xstrdup (str);
       str = attrs->getValue (NTXT ("pagesz"));
       if (str != NULL)
        exp->page_size = atoi (str);
@@ -1061,7 +1057,7 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
          exp->has_java = true;
          str = attrs->getValue (NTXT ("jversion"));
          if (str != NULL)
-           exp->jversion = strdup (str);
+           exp->jversion = xstrdup (str);
        }
       else if (strcmp (str, NTXT ("datarace")) == 0)
        {
@@ -1148,7 +1144,7 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
                {
                  fldDscr->vtype = TYPE_DATE;
                  const char *fmt = attrs->getValue (NTXT ("format"));
-                 fldDscr->format = strdup (fmt ? fmt : "");
+                 fldDscr->format = xstrdup (fmt ? fmt : "");
                }
            }
          propDscr->vtype = fldDscr->vtype;
@@ -1173,7 +1169,7 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
 
          str = attrs->getValue (NTXT ("uname"));
          if (str)
-           propDscr->uname = strdup (PTXT ((char*) str));
+           propDscr->uname = xstrdup (PTXT ((char*) str));
          str = attrs->getValue (NTXT ("noshow"));
          if (str && atoi (str) != 0)
            propDscr->flags |= PRFLAG_NOSHOW;
@@ -4589,7 +4585,7 @@ Experiment::readPacket (Data_window *dwin, Data_window::Span *span)
                else
                  {
                    // bug 6909545: garbage in 64-bit JAVA_INFO
-                   char *nstack = (char*) malloc (stack_size);
+                   char *nstack = (char*) xmalloc (stack_size);
                    char *dst = nstack;
                    char *srcmax = stack + stack_size - sizeof (uint64_t);
                    for (char *src = stack; src <= srcmax;)
@@ -5845,7 +5841,7 @@ Experiment::checkFileInArchive (const char *fname, bool archiveFile)
       DbeFile *df = archiveMap->get (aname);
       free (aname);
       if (df)
-       return strdup (df->get_location ());
+       return xstrdup (df->get_location ());
       return NULL;
     }
   if (founder_exp)
@@ -6591,12 +6587,7 @@ Experiment::copy_file_to_common_archive (const char *name, const char *aname,
          fprintf (stderr, GTXT ("gp-archive: Fatal error: pathconf(\".\", _PC_PATH_MAX) failed\n"));
          return 1;
        }
-      char *buf = (char *) malloc ((size_t) size);
-      if (buf == NULL)
-       {
-         fprintf (stderr, GTXT ("gp-archive: Fatal error: unable to allocate memory\n"));
-         return 1;
-       }
+      char *buf = (char *) xmalloc ((size_t) size);
       char *ptr = getcwd (buf, (size_t) size);
       if (ptr == NULL)
        {
index 1d8ae45dbdd982245299577c67b6ecb94758c6d8..dd9a2c7bb3f06313d28613d28651610b332bfb4f 100644 (file)
@@ -129,14 +129,14 @@ Function::get_name (NameFormat nfmt)
   bool soname_fmt = Histable::soname_fmt (nfmt);
   int fname_fmt = Histable::fname_fmt (nfmt);
   if (fname_fmt == Histable::MANGLED)
-    name_buf = strdup (mangled_name);
+    name_buf = xstrdup (mangled_name);
   else
     {
       if (module && module->is_fortran ()
          && (streq (name, "MAIN") || streq (name, "MAIN_")))
-       name_buf = strdup (match_name);
+       name_buf = xstrdup (match_name);
       else
-       name_buf = strdup (name);
+       name_buf = xstrdup (name);
 
       if (fname_fmt == Histable::SHORT)
        {
index fb4b8a0fafa9710b167b58d8d6ec1f484ab0cbf8..41795071185f743e6e676933e2248700abd3497c 100644 (file)
@@ -92,7 +92,6 @@ CSOURCES = \
        dbe_hwcdrv.c \
        dbe_hwcfuncs.c \
        dbe_hwctable.c \
-       dbe_memmgr.c \
        gethrtime.c \
        $(NULL)
 
index cef4b275305427473a9bce85b9d751cdc2adaad7..4c25d017d0eaac43af8fb1278296d993aaa32245 100644 (file)
@@ -178,7 +178,7 @@ am__objects_1 = Application.lo BaseMetric.lo BaseMetricTreeNode.lo \
        QLParser.tab.lo dbe_collctrl.lo i18n.lo parse.lo UserLabel.lo \
        util.lo Dbe.lo
 am__objects_2 = dbe_hwcdrv.lo dbe_hwcfuncs.lo dbe_hwctable.lo \
-       dbe_memmgr.lo gethrtime.lo
+       gethrtime.lo
 am_libgprofng_la_OBJECTS = $(am__objects_1) $(am__objects_2)
 libgprofng_la_OBJECTS = $(am_libgprofng_la_OBJECTS)
 AM_V_lt = $(am__v_lt_@AM_V@)
@@ -519,7 +519,6 @@ CSOURCES = \
        dbe_hwcdrv.c \
        dbe_hwcfuncs.c \
        dbe_hwctable.c \
-       dbe_memmgr.c \
        gethrtime.c \
        $(NULL)
 
@@ -786,7 +785,6 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbe_hwcdrv.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbe_hwcfuncs.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbe_hwctable.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbe_memmgr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/envsets.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gethrtime.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gp-archive.Po@am__quote@
index d5255dcd05fa5cc09472f21f20c1c3e28b267b90..064581c387465e4e1494e3596b30e73d0f89b942 100644 (file)
@@ -368,7 +368,7 @@ Module::read_ar (int ar, int obj, char *obj_base)
   if (!strncmp (hdr.ar_name, NTXT ("//"), 2))
     {
       longnames_size = get_ar_size (hdr.ar_size, sizeof (hdr.ar_size));
-      longnames = (char *) malloc (longnames_size + 1);
+      longnames = (char *) xmalloc (longnames_size + 1);
       int64_t cnt = read_from_file (ar, longnames, longnames_size);
       if (cnt != (int64_t) longnames_size)
        {
@@ -519,8 +519,8 @@ Module::setFile ()
       char *path = loadobject->dbeFile->get_location ();
       if (path)
        {
-         disPath = strdup (path);
-         disName = strdup (path);
+         disPath = xstrdup (path);
+         disName = xstrdup (path);
          disMTime = loadobject->dbeFile->sbuf.st_mtime;
        }
 
@@ -535,7 +535,7 @@ Module::setFile ()
          size_t last = strlen (base) - 1;
          base[last] = '\0';
          stabsTmp = dbeSession->get_tmp_file_name (base, false);
-         dbeSession->tmp_files->append (strdup (stabsTmp));
+         dbeSession->tmp_files->append (xstrdup (stabsTmp));
 
          DbeFile *dbf = dbeSession->getDbeFile (namebuf,
                                        DbeFile::F_DOT_A_LIB | DbeFile::F_FILE);
@@ -553,8 +553,8 @@ Module::setFile ()
              dbeFile->check_access (stabsTmp); // init 'sbuf'
              dbeFile->sbuf.st_mtime = 0; // Don't check timestamps
              dbeFile->container = dbf;
-             stabsPath = strdup (stabsTmp);
-             stabsName = strdup (path);
+             stabsPath = xstrdup (stabsTmp);
+             stabsName = xstrdup (path);
              stabsMTime = dbeFile->sbuf.st_mtime;
            }
          else
@@ -573,8 +573,8 @@ Module::setFile ()
          path = dbeFile->get_location ();
          if (path != NULL)
            {
-             stabsPath = strdup (path);
-             stabsName = strdup (path);
+             stabsPath = xstrdup (path);
+             stabsName = xstrdup (path);
              stabsMTime = hasDwarf ? 0 : dbeFile->sbuf.st_mtime;
            }
        }
@@ -585,14 +585,14 @@ Module::setFile ()
        {
          if (disPath == NULL)
            return false;
-         stabsPath = strdup (disPath);
-         stabsName = strdup (disName);
+         stabsPath = xstrdup (disPath);
+         stabsName = xstrdup (disName);
          stabsMTime = disMTime;
        }
       else if (disPath == NULL)
        {
-         disPath = strdup (stabsPath);
-         disName = strdup (stabsName);
+         disPath = xstrdup (stabsPath);
+         disName = xstrdup (stabsName);
          disMTime = stabsMTime;
        }
     }
@@ -1278,7 +1278,7 @@ Module::set_src_data (Function *func, int vis_bits, int cmpline_visible,
     {
       Hist_data::HistItem *item = src_items->new_hist_item (NULL, AT_EMPTY,
                                                            empty);
-      item->value[name_idx].l = strdup (NTXT (""));
+      item->value[name_idx].l = xstrdup (NTXT (""));
       data_items->append_hist_item (item);
       item = src_items->new_hist_item (NULL, AT_COM, empty);
       item->value[name_idx].l = dbe_sprintf (GTXT ("Compile flags: %s"),
index 32a51783f3a2538c3481033702672d1cc4566f90..76d9fbd8bd8fd9b1ebf1ca5624e453b4ce618f79 100644 (file)
@@ -60,7 +60,7 @@ er_print_common_display::open (Print_params *params)
   if (params->dest == DEST_PRINTER)
     {
       tmp_file = dbeSession->get_tmp_file_name (NTXT ("print"), false);
-      dbeSession->tmp_files->append (strdup (tmp_file));
+      dbeSession->tmp_files->append (xstrdup (tmp_file));
       out_file = fopen (tmp_file, NTXT ("w"));
     }
   else if (params->dest == DEST_OPEN_FILE)
@@ -128,7 +128,7 @@ er_print_common_display::get_output (int maxsize)
   if (f == NULL)
     return dbe_sprintf (GTXT ("Error: cannot open temporary file: %s\n"),
                        tmp_file);
-  char *report = (char *) malloc (max);
+  char *report = (char *) xmalloc (max);
   if (report)
     {
       if (1 != fread (report, max - 1, 1, f))
@@ -2382,7 +2382,7 @@ print_html_label (FILE *out_file, MetricList *metrics_list)
        ncols++;
       if (ncols == 0)
        continue;
-      char *name = strdup (mitem->get_name ());
+      char *name = xstrdup (mitem->get_name ());
       char *name2 = split_metric_name (name);
       const char *style = index == metrics_list->get_sort_ref_index () ? "G" : "";
 
@@ -2608,7 +2608,7 @@ print_delim_label (FILE *out_file, MetricList *metrics_list, char delim)
       if (!(mitem->is_visible () || mitem->is_tvisible ()
            || mitem->is_pvisible ()))
        continue;
-      char *name = strdup (mitem->get_name ());
+      char *name = xstrdup (mitem->get_name ());
       char *name2 = split_metric_name (name);
 
       if (mitem->is_tvisible ())
index c0d7329eb1b1d7922144a88936df627b8f245e74..1b0998026a912bbdcdb965bda4bd33874cacef00 100644 (file)
 %language "C++"
 
 %code top {
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #include <string>
 }
 %code requires {
+#include "libiberty.h"
 #include "QLParser.h"
 #include "DbeSession.h"
 #include "Expression.h"
@@ -274,7 +276,7 @@ namespace QL
       case '"':
        {
          int  maxsz = 16;
-         char *str = (char *) malloc (maxsz);
+         char *str = (char *) xmalloc (maxsz);
          char *ptr = str;
 
          for (;;)
@@ -301,7 +303,7 @@ namespace QL
                    {
                      size_t len = ptr - str;
                      maxsz = maxsz > 8192 ? maxsz + 8192 : maxsz * 2;
-                     char *new_s = (char *) realloc (str, maxsz);
+                     char *new_s = (char *) xrealloc (str, maxsz);
                      str = new_s;
                      ptr = str + len;
                    }
index 1099ca33a1bd5fc2db0fab05ae14573c116fe4c5..eedda263644b1dacad6808262a0ce30be7403a65 100644 (file)
@@ -112,15 +112,15 @@ AttributesP::append (char *qName, char *value)
  */
 SAXException::SAXException ()
 {
-  message = strdup ("null");
+  message = xstrdup ("null");
 }
 
 SAXException::SAXException (const char *_message)
 {
   if (_message == NULL)
-    message = strdup ("null");
+    message = xstrdup ("null");
   else
-    message = strdup (_message);
+    message = xstrdup (_message);
 }
 
 SAXException::~SAXException ()
@@ -197,7 +197,7 @@ SAXParserP::SAXParserP ()
 {
   dh = NULL;
   bufsz = 0x2000;
-  buffer = (char*) malloc (bufsz);
+  buffer = (char*) xmalloc (bufsz);
   cntsz = 0;
   idx = 0;
   line = 1;
@@ -214,7 +214,7 @@ SAXParserP::reset ()
 {
   dh = NULL;
   bufsz = 8192;
-  buffer = (char*) realloc (buffer, bufsz);
+  buffer = (char*) xrealloc (buffer, bufsz);
   cntsz = 0;
   idx = 0;
   line = 1;
@@ -244,7 +244,7 @@ SAXParserP::parse (File *f, DefaultHandler *_dh)
        {
          int oldbufsz = bufsz;
          bufsz = bufsz >= 0x100000 ? bufsz + 0x100000 : bufsz * 2;
-         buffer = (char*) realloc (buffer, bufsz);
+         buffer = (char*) xrealloc (buffer, bufsz);
          rem = bufsz - oldbufsz;
        }
     }
index 6d1d357a1756f95623f3646a2d3cd9a46b6198e6..1af0a2309aaadd150d68292ed16afde9be77cc9a 100644 (file)
@@ -1346,13 +1346,13 @@ Settings::proc_tabs (bool _rdtMode)
   if (_rdtMode == true)
     {
       if (str_rtabs == NULL)
-       str_rtabs = strdup ("header");
+       str_rtabs = xstrdup ("header");
       cmd = str_rtabs;
     }
   else
     {
       if (str_tabs == NULL)
-       str_tabs = strdup ("header");
+       str_tabs = xstrdup ("header");
       cmd = str_tabs;
     }
   if (strcmp (cmd, NTXT ("none")) == 0)
index b9f4f131ac9a50238432fc409a40e883f57691cc..ac14935aff5b855027aee56edfe2fa0dd56da4f3 100644 (file)
@@ -101,7 +101,7 @@ SourceFile::readSource ()
       status = OS_NOSRC;
       return false;
     }
-  char *srcMap = (char *) malloc (srcLen + 1);
+  char *srcMap = (char *) xmalloc (srcLen + 1);
   int64_t sz = read_from_file (fd, srcMap, srcLen);
   if (sz != (int64_t) srcLen)
     append_msg (CMSG_ERROR, GTXT ("%s: Can read only %lld bytes instead %lld"),
index 9901b62c1a72aced2c548d0d826074144358c988..c89afd76f6e82c5ce13d532d2cc350a370825357 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 
+#include "libiberty.h"
 #include "gp-defs.h"
 #include "StringBuilder.h"
 #include "i18n.h"
@@ -34,7 +35,7 @@ StringBuilder::StringBuilder ()
 {
   count = 0;
   maxCapacity = 16;
-  value = (char *) malloc (maxCapacity);
+  value = (char *) xmalloc (maxCapacity);
   memset (value, 0, maxCapacity);
 }
 
@@ -42,7 +43,7 @@ StringBuilder::StringBuilder (int capacity)
 {
   count = 0;
   maxCapacity = capacity;
-  value = (char *) malloc (maxCapacity);
+  value = (char *) xmalloc (maxCapacity);
   memset (value, 0, maxCapacity);
 }
 
@@ -66,7 +67,7 @@ StringBuilder::expandCapacity (int minimumCapacity)
     newCapacity = MAXINT;
   else if (minimumCapacity > newCapacity)
     newCapacity = minimumCapacity;
-  char *newValue = (char *) malloc (newCapacity);
+  char *newValue = (char *) xmalloc (newCapacity);
   maxCapacity = newCapacity;
   memcpy (newValue, value, count);
   memset (newValue + count, 0, maxCapacity - count);
@@ -79,7 +80,7 @@ StringBuilder::trimToSize ()
 {
   if (count < maxCapacity)
     {
-      char *newValue = (char *) malloc (count);
+      char *newValue = (char *) xmalloc (count);
       maxCapacity = count;
       memcpy (newValue, value, count);
       free (value);
@@ -425,7 +426,7 @@ StringBuilder::reverse ()
 char *
 StringBuilder::toString ()
 {
-  char *str = (char *) malloc (count + 1);
+  char *str = (char *) xmalloc (count + 1);
   memcpy (str, value, count);
   str[count] = '\0';
   return str;
index db949ad77ee775ef1d0695dff00b345e1efd0f3e..d4702d3f1b811f5788829231414273eb9a84f228 100644 (file)
@@ -154,7 +154,7 @@ StringMap<Value_t>::put (const char *key, Value_t val)
       chunks[nchunks - 1] = new Entry[CHUNK_SIZE];
     }
   entry = &chunks[entries / CHUNK_SIZE][entries % CHUNK_SIZE];
-  entry->key = strdup (key);
+  entry->key = xstrdup (key);
   entry->val = val;
   index->insert (lo, entry);
   hashTable[idx] = entry;
index 5e8883e6b4309fc890c8bc06bb29146dd4a5f916..4ec0a76d039fc0e90947544ec779072493cf89e2 100644 (file)
@@ -85,7 +85,7 @@ int assert_level = 0; // set to 1 to bypass problematic asserts
 PropDescr::PropDescr (int _propID, const char *_name)
 {
   propID = _propID;
-  name = strdup (_name ? _name : NTXT (""));
+  name = xstrdup (_name ? _name : NTXT (""));
   uname = NULL;
   vtype = TYPE_NONE;
   flags = 0;
@@ -116,10 +116,10 @@ PropDescr::addState (int value, const char *stname, const char *stuname)
     return;
   if (stateNames == NULL)
     stateNames = new Vector<char*>;
-  stateNames->store (value, strdup (stname));
+  stateNames->store (value, xstrdup (stname));
   if (stateUNames == NULL)
     stateUNames = new Vector<char*>;
-  stateUNames->store (value, strdup (stuname));
+  stateUNames->store (value, xstrdup (stuname));
 }
 
 char *
@@ -145,7 +145,7 @@ PropDescr::getStateUName (int value)
 FieldDescr::FieldDescr (int _propID, const char *_name)
 {
   propID = _propID;
-  name = _name ? strdup (_name) : NULL;
+  name = _name ? xstrdup (_name) : NULL;
   offset = 0;
   vtype = TYPE_NONE;
   format = NULL;
@@ -820,7 +820,7 @@ public:
   virtual char *
   fetchString (long i)
   {
-    return strdup (data->fetch (i));
+    return xstrdup (data->fetch (i));
   }
 
   virtual double
@@ -1008,8 +1008,8 @@ DataDescriptor::DataDescriptor (int _id, const char *_name, const char *_uname,
 {
   isMaster = true;
   id = _id;
-  name = _name ? strdup (_name) : strdup (NTXT (""));
-  uname = _uname ? strdup (_uname) : strdup (NTXT (""));
+  name = _name ? xstrdup (_name) : xstrdup (NTXT (""));
+  uname = _uname ? xstrdup (_uname) : xstrdup (NTXT (""));
   flags = _flags;
 
   // master data, shared with reference copies:
@@ -1029,8 +1029,8 @@ DataDescriptor::DataDescriptor (int _id, const char *_name, const char *_uname,
 {
   isMaster = false;
   id = _id;
-  name = _name ? strdup (_name) : strdup (NTXT (""));
-  uname = _uname ? strdup (_uname) : strdup (NTXT (""));
+  name = _name ? xstrdup (_name) : xstrdup (NTXT (""));
+  uname = _uname ? xstrdup (_uname) : xstrdup (NTXT (""));
   flags = dDscr->flags;
 
   // references point to master DataDescriptor
index 4fe850d650936b36dd3a05c67907e278aa4969f7..f6d9b0e08ca35f3d130387c54e1ed1bae02aa8a5 100644 (file)
@@ -51,7 +51,7 @@ collect::check_target (int argc, char **argv)
     {
     case EXEC_OK:
       njargs = cc->get_java_arg_cnt ();
-      arglist = (char **) calloc (nargs + 5 + njargs, sizeof (char *));
+      arglist = (char **) xcalloc (nargs + 5 + njargs, sizeof (char *));
       jargs = cc->get_java_args ();
 
       // store the first argument -- target name
@@ -96,7 +96,7 @@ collect::check_target (int argc, char **argv)
          exit (1);
        }
       njargs = cc->get_java_arg_cnt ();
-      arglist = (char **) calloc (nargs + 5 + njargs, sizeof (char *));
+      arglist = (char **) xcalloc (nargs + 5 + njargs, sizeof (char *));
       jargs = cc->get_java_args ();
 
       a = find_java ();
@@ -140,7 +140,7 @@ collect::check_target (int argc, char **argv)
        }
       jargs = cc->get_java_args ();
       njargs = cc->get_java_arg_cnt ();
-      arglist = (char **) calloc (nargs + 4 + njargs, sizeof (char *));
+      arglist = (char **) xcalloc (nargs + 4 + njargs, sizeof (char *));
 
       a = find_java ();
       if (a == NULL)
@@ -377,7 +377,7 @@ collect::status_str (Exec_status rv, char *target_name)
     case EXEC_OPEN_FAIL:
       return dbe_sprintf (GTXT ("Can't open target executable `%s'\n"), target_name);
     case EXEC_ELF_LIB:
-      return strdup (GTXT ("Internal error: Not a working version of ELF library\n"));
+      return xstrdup (GTXT ("Internal error: Not a working version of ELF library\n"));
     case EXEC_ELF_HEADER:
       return dbe_sprintf (GTXT ("Target `%s' is not a valid ELF executable\n"), target_name);
     case EXEC_ELF_ARCH:
@@ -450,11 +450,11 @@ collect::find_java (void)
   switch (rv)
     {
     case EXEC_OK:
-      java_path = strdup (buf);
+      java_path = xstrdup (buf);
       if (verbose == 1)
        dbe_write (2, GTXT ("Path to `%s' (set from %s) used for Java profiling\n"),
                   java_path, java_how);
-      return ( strdup (buf));
+      return xstrdup (buf);
     default:
       dbe_write (2, GTXT ("Path to `%s' (set from %s) does not point to a JVM executable\n"),
                 buf, java_how);
index 2fa9a883147200cf45e2af6fdaa481c5eb4b2f78..3dae531c3154c3d157bb28fccf2f75b8e9f4e902 100644 (file)
@@ -64,7 +64,7 @@ read_str (char *from, char **to)
          {
            if (s[i] != '\n' && s[i] != ' ' && s[i] != '\t')
              {
-               *to = strndup (s, i + 1);
+               *to = xstrndup (s, i + 1);
                return;
              }
          }
@@ -131,7 +131,7 @@ read_cpuinfo ()
     }
   if (cpu_info.cpu_vendorstr == NULL)
 #if defined(__aarch64__)
-    cpu_info.cpu_vendorstr = strdup (AARCH64_VENDORSTR_ARM);
+    cpu_info.cpu_vendorstr = xstrdup (AARCH64_VENDORSTR_ARM);
 #else
     cpu_info.cpu_vendorstr = GTXT ("Unknown processor");
 #endif
@@ -149,11 +149,11 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC)
 
   /* set this host's parameters */
   gethostname (hostname, 1023);
-  node_name = strdup (hostname);
+  node_name = xstrdup (hostname);
   char *p = strchr (node_name, (int) '.');
   if (p != NULL)
     *p = 0;
-  default_stem = strdup ("test");
+  default_stem = xstrdup ("test");
 
   cpu_info_t *cpu_p = read_cpuinfo ();
   ncpus = cpu_p->cpu_cnt;
@@ -186,7 +186,7 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC)
   follow_spec_usr = NULL;
   follow_spec_cmp = NULL;
   prof_idle = 1;
-  archive_mode = strdup ("on");
+  archive_mode = xstrdup ("on");
   pauseresume_sig = 0;
   sample_sig = 0;
   uinterrupt = 0;
@@ -201,7 +201,7 @@ Coll_Ctrl::Coll_Ctrl (int _interactive, bool _defHWC, bool _kernelHWC)
   base_name = NULL;
   udir_name = NULL;
   store_dir = NULL;
-  prev_store_dir = strdup ("");
+  prev_store_dir = xstrdup ("");
   store_ptr = NULL;
   expt_group = NULL;
   target_name = NULL;
@@ -256,8 +256,8 @@ Coll_Ctrl::Coll_Ctrl (Coll_Ctrl * cc)
   interactive = cc->interactive;
   defHWC = cc->defHWC;
   kernelHWC = cc->kernelHWC;
-  node_name = strdup (cc->node_name);
-  default_stem = strdup (cc->default_stem);
+  node_name = xstrdup (cc->node_name);
+  default_stem = xstrdup (cc->default_stem);
   ncpus = cc->ncpus;
   cpu_clk_freq = cc->cpu_clk_freq;
   npages = cc->npages;
@@ -272,15 +272,15 @@ Coll_Ctrl::Coll_Ctrl (Coll_Ctrl * cc)
   follow_default = cc->follow_default;
   if (cc->follow_spec_usr)
     {
-      follow_spec_usr = strdup (cc->follow_spec_usr);
-      follow_spec_cmp = strdup (cc->follow_spec_cmp);
+      follow_spec_usr = xstrdup (cc->follow_spec_usr);
+      follow_spec_cmp = xstrdup (cc->follow_spec_cmp);
     }
   else
     {
       follow_spec_usr = NULL;
       follow_spec_cmp = NULL;
     }
-  archive_mode = strdup (cc->archive_mode);
+  archive_mode = xstrdup (cc->archive_mode);
   pauseresume_sig = cc->pauseresume_sig;
   sample_sig = cc->sample_sig;
   time_run = cc->time_run;
@@ -295,12 +295,12 @@ Coll_Ctrl::Coll_Ctrl (Coll_Ctrl * cc)
   hwcprof_default = cc->hwcprof_default;
   hwcprof_enabled_cnt = cc->hwcprof_enabled_cnt;
   if (cc->hwc_string != NULL)
-    hwc_string = strdup (cc->hwc_string);
+    hwc_string = xstrdup (cc->hwc_string);
   else
     hwc_string = NULL;
   for (int i = 0; i < hwcprof_enabled_cnt; i++)
     hwcentry_dup (&hwctr[i], &(cc->hwctr[i]));
-  project_home = cc->project_home ? strdup (cc->project_home) : NULL;
+  project_home = cc->project_home ? xstrdup (cc->project_home) : NULL;
   synctrace_enabled = cc->synctrace_enabled;
   synctrace_thresh = cc->synctrace_thresh;
   synctrace_scope = cc->synctrace_scope;
@@ -324,16 +324,16 @@ Coll_Ctrl::Coll_Ctrl (Coll_Ctrl * cc)
   // these represent user settings
   expt_group = NULL;
   if (cc->expt_group != NULL)
-    expt_group = strdup (cc->expt_group);
+    expt_group = xstrdup (cc->expt_group);
   uexpt_name = NULL;
   if (cc->uexpt_name != NULL)
-    uexpt_name = strdup (cc->uexpt_name);
+    uexpt_name = xstrdup (cc->uexpt_name);
   udir_name = NULL;
   if (cc->udir_name != NULL)
-    udir_name = strdup (cc->udir_name);
+    udir_name = xstrdup (cc->udir_name);
 
   /* clear the string pointers */
-  prev_store_dir = strdup ("");
+  prev_store_dir = xstrdup ("");
   store_ptr = NULL;
   target_name = NULL;
   data_desc = NULL;
@@ -408,11 +408,11 @@ char *
 Coll_Ctrl::enable_expt ()
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (cpu_clk_freq == 0)
-    return strdup (GTXT ("Can not determine CPU clock frequency.\n"));
+    return xstrdup (GTXT ("Can not determine CPU clock frequency.\n"));
   if (sys_resolution == 0)
-    return strdup (GTXT ("System clock profile resolution can not be determined.\n"));
+    return xstrdup (GTXT ("System clock profile resolution can not be determined.\n"));
   enabled = 1;
   return NULL;
 }
@@ -450,14 +450,14 @@ Coll_Ctrl::check_consistency ()
 {
   /* check for Java arguments, but not Java profiling */
   if (java_args != NULL && java_mode == 0)
-    return strdup (GTXT ("Java arguments can not be set if Java profiling is not enabled.\n"));
+    return xstrdup (GTXT ("Java arguments can not be set if Java profiling is not enabled.\n"));
 
   /* if count data, no other data is allowed */
   if (count_enabled != 0
       && ((clkprof_default != 1 && clkprof_enabled != 0)
          || hwcprof_enabled_cnt != 0 || synctrace_enabled != 0
          || heaptrace_mode != NULL || iotrace_enabled != 0))
-    return strdup (GTXT ("Count data cannot be collected along with any other data.\n"));
+    return xstrdup (GTXT ("Count data cannot be collected along with any other data.\n"));
 
   /* if count data, various other options are not allowed */
   if (count_enabled != 0
@@ -466,10 +466,10 @@ Coll_Ctrl::check_consistency ()
          || (follow_mode != 0 && follow_default != 1)
          || pauseresume_sig != 0 || sample_sig != 0
          || (sample_default != 1 && sample_period != 0) || time_run != 0))
-    return strdup (GTXT ("Count data cannot be collected with any of -F -S -y -l -j -J -x -t .\n"));
+    return xstrdup (GTXT ("Count data cannot be collected with any of -F -S -y -l -j -J -x -t .\n"));
   /* if not count data, I and N options are not allowed */
   if (count_enabled == 0 && (Iflag != 0 || Nflag != 0))
-    return strdup (GTXT ("-I or -N can only be specified with count data.\n"));
+    return xstrdup (GTXT ("-I or -N can only be specified with count data.\n"));
   return NULL;
 }
 
@@ -483,12 +483,12 @@ Coll_Ctrl::check_expt (char **warn)
     return ret;
   /* check for heaptrace and java -- warn that it covers native allocations only */
   if (heaptrace_mode != NULL && java_mode == 1 && java_default == 0)
-    *warn = strdup (GTXT ("Note: Heap profiling will only trace native allocations, not Java allocations.\n"));
+    *warn = xstrdup (GTXT ("Note: Heap profiling will only trace native allocations, not Java allocations.\n"));
 
   /* if no profiling data selected, warn the user */
   if (clkprof_enabled == 0 && hwcprof_enabled_cnt == 0 && synctrace_enabled == 0
       && heaptrace_mode == NULL && iotrace_enabled == 0 && count_enabled == 0)
-    *warn = strdup (GTXT ("Warning: No function level data requested; only statistics will be collected.\n\n"));
+    *warn = xstrdup (GTXT ("Warning: No function level data requested; only statistics will be collected.\n\n"));
   build_data_desc ();
 
   /* verify that the directory exists */
@@ -677,22 +677,20 @@ char **
 Coll_Ctrl::get_collect_args ()
 {
   char **p;
-  char **argv = (char **) calloc (MAX_COLLECT_ARGS, sizeof (char *));
-  if (argv == NULL) // poor way of dealing with calloc failure
-    abort ();
+  char **argv = (char **) xcalloc (MAX_COLLECT_ARGS, sizeof (char *));
   p = argv;
-  *p++ = strdup ("collect");
+  *p++ = xstrdup ("collect");
   if (debug_mode == 1)
-    *p++ = strdup ("-x");
+    *p++ = xstrdup ("-x");
   if (clkprof_enabled != 0)
     {
-      *p++ = strdup ("-p");
+      *p++ = xstrdup ("-p");
       *p++ = dbe_sprintf ("%du", clkprof_timer);
     }
   if (hwcprof_enabled_cnt > 0)
     {
       StringBuilder sb;
-      *p++ = strdup ("-h");
+      *p++ = xstrdup ("-h");
       for (int ii = 0; ii < hwcprof_enabled_cnt; ii++)
        {
          char*rateString = hwc_rate_string (&hwctr[ii], 1); //"1" is for temporary goldfile compatibility. TBR YXXX!!
@@ -711,90 +709,90 @@ Coll_Ctrl::get_collect_args ()
     }
   if (heaptrace_mode != NULL)
     {
-      *p++ = strdup ("-H");
-      *p++ = strdup (heaptrace_mode);
+      *p++ = xstrdup ("-H");
+      *p++ = xstrdup (heaptrace_mode);
     }
   if (iotrace_enabled != 0)
     {
-      *p++ = strdup ("-i");
-      *p++ = strdup ("on");
+      *p++ = xstrdup ("-i");
+      *p++ = xstrdup ("on");
     }
   if (synctrace_enabled != 0)
     {
-      *p++ = strdup ("-s");
+      *p++ = xstrdup ("-s");
       if (synctrace_thresh < 0)
-       *p++ = strdup ("calibrate");
+       *p++ = xstrdup ("calibrate");
       else if (synctrace_thresh == 0)
-       *p++ = strdup ("all");
+       *p++ = xstrdup ("all");
       else
        *p++ = dbe_sprintf ("%d", synctrace_thresh);
       *p++ = dbe_sprintf (",%d", synctrace_scope);
     }
   if (follow_mode != 0)
     {
-      *p++ = strdup ("-F");
+      *p++ = xstrdup ("-F");
       char * fs = get_follow_usr_spec ();
       if (fs)
-       *p++ = strdup (fs);
+       *p++ = xstrdup (fs);
       else
        {
          switch (get_follow_mode ())
            {
            case FOLLOW_ON:
-             *p++ = strdup ("on");
+             *p++ = xstrdup ("on");
              break;
            case FOLLOW_ALL:
-             *p++ = strdup ("all");
+             *p++ = xstrdup ("all");
              break;
            case FOLLOW_NONE:
            default:
-             *p++ = strdup ("off");
+             *p++ = xstrdup ("off");
              break;
            }
        }
     }
-  *p++ = strdup ("-a");
-  *p++ = strdup (get_archive_mode ());
+  *p++ = xstrdup ("-a");
+  *p++ = xstrdup (get_archive_mode ());
   if (java_mode != 0)
     {
-      *p++ = strdup ("-j");
-      *p++ = strdup ("on");
+      *p++ = xstrdup ("-j");
+      *p++ = xstrdup ("on");
     }
   if (pauseresume_sig != 0)
     {
-      *p++ = strdup ("-y");
+      *p++ = xstrdup ("-y");
       *p++ = dbe_sprintf ("%d%s", pauseresume_sig,
                          (pauseresume_pause == 0 ? ",r" : ""));
     }
   if (sample_sig != 0)
     {
-      *p++ = strdup ("-l");
+      *p++ = xstrdup ("-l");
       *p++ = dbe_sprintf ("%d", sample_sig);
     }
   if (sample_period != 0)
     {
-      *p++ = strdup ("-S");
+      *p++ = xstrdup ("-S");
       *p++ = dbe_sprintf ("%d", sample_period);
     }
   if (size_limit != 0)
     {
-      *p++ = strdup ("-L");
+      *p++ = xstrdup ("-L");
       *p++ = dbe_sprintf ("%d", size_limit);
     }
   if (expt_group != NULL)
     {
-      *p++ = strdup ("-g");
-      *p++ = strdup (expt_group);
+      *p++ = xstrdup ("-g");
+      *p++ = xstrdup (expt_group);
     }
   if (udir_name != 0)
     {
-      *p++ = strdup ("-d");
-      *p++ = strdup (udir_name);
+      *p++ = xstrdup ("-d");
+      *p++ = xstrdup (udir_name);
     }
   if (expt_name != 0)
     {
-      *p++ = strdup ("-o");
-      *p++ = strdup (expt_name);
+      *p++ = xstrdup ("-o");
+      *p++ = xstrdup (expt_name);
     }
   if (p - argv >= MAX_COLLECT_ARGS) // argument list too small -- fatal error
     abort ();
@@ -852,10 +850,10 @@ Coll_Ctrl::set_clkprof (const char *string, char** warn)
   int prevclkprof_default;
   *warn = NULL;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   /* if the first character is a +, warn user that it is no longer supported */
   if (string[0] == '+')
-    return strdup (GTXT ("Warning: clock-based memoryspace and dataspace profiling is no longer supported\n"));
+    return xstrdup (GTXT ("Warning: clock-based memoryspace and dataspace profiling is no longer supported\n"));
   if (strcmp (string, "off") == 0)
     {
       clkprof_enabled = 0;
@@ -946,7 +944,7 @@ char *
 Coll_Ctrl::set_synctrace (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   char *comma_p = NULL;
   if (string == NULL)
     {
@@ -962,7 +960,7 @@ Coll_Ctrl::set_synctrace (const char *string)
        }
       return NULL;
     }
-  char *val = strdup (string);
+  char *val = xstrdup (string);
   /* see if there's a comma in the string */
   char *next = strchr (val, (int) ',');
   if (next != NULL)
@@ -1042,14 +1040,14 @@ char *
 Coll_Ctrl::set_heaptrace (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   free(heaptrace_mode);
   heaptrace_mode = NULL;  // Same as "off"
   if (string != NULL && strcmp (string, "off") == 0)
     return NULL;
 
   if (string == NULL || strlen (string) == 0 || strcmp (string, "on") == 0)
-    heaptrace_mode = strdup ("on");
+    heaptrace_mode = xstrdup ("on");
   else if (isdigit (*string))
     {
       char *s;
@@ -1064,7 +1062,7 @@ Coll_Ctrl::set_heaptrace (const char *string)
       if (*s != 0)
        return dbe_sprintf (
               GTXT ("Incorrect range in heap trace parameter '%s'\n"), string);
-      heaptrace_mode = strdup (string);
+      heaptrace_mode = xstrdup (string);
     }
   else
     return dbe_sprintf (GTXT ("Unrecognized heap tracing parameter `%s'\n"),
@@ -1083,7 +1081,7 @@ char *
 Coll_Ctrl::set_iotrace (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strlen (string) == 0 || strcmp (string, "on") == 0)
     {
       iotrace_enabled = 1;
@@ -1108,7 +1106,7 @@ Coll_Ctrl::set_count (const char *string)
 {
   int ret = -1;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strlen (string) == 0 || strcmp (string, "off") == 0)
     {
       count_enabled = 0;
@@ -1161,9 +1159,9 @@ char *
 Coll_Ctrl::set_time_run (const char *valarg)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (valarg == NULL) /* invalid setting */
-    return strdup (GTXT ("time parameter can not be NULL\n"));
+    return xstrdup (GTXT ("time parameter can not be NULL\n"));
   /* the string should be a number >= 0 */
   int prev_start_delay = start_delay;
   int prev_time_run = time_run;
@@ -1233,9 +1231,9 @@ char *
 Coll_Ctrl::set_attach_pid (char *valarg)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (valarg == NULL)
-    return strdup (GTXT ("Specified PID can not be NULL\n"));
+    return xstrdup (GTXT ("Specified PID can not be NULL\n"));
 
   /* the string should be a number corresponding to an active process' pid */
   char *endchar = NULL;
@@ -1269,19 +1267,19 @@ Coll_Ctrl::hwcentry_dup (Hwcentry *hnew, Hwcentry *_hwc)
 {
   *hnew = *_hwc;
   if (_hwc->name != NULL)
-    hnew->name = strdup (_hwc->name);
+    hnew->name = xstrdup (_hwc->name);
   else
     hnew->name = NULL;
   if (_hwc->int_name != NULL)
-    hnew->int_name = strdup (_hwc->int_name);
+    hnew->int_name = xstrdup (_hwc->int_name);
   else
     hnew->int_name = NULL;
   if (_hwc->metric != NULL)
-    hnew->metric = strdup (_hwc->metric);
+    hnew->metric = xstrdup (_hwc->metric);
   else
     hnew->metric = NULL;
   if (_hwc->short_desc != NULL)
-    hnew->short_desc = strdup (_hwc->short_desc);
+    hnew->short_desc = xstrdup (_hwc->short_desc);
   else
     hnew->short_desc = NULL;
 }
@@ -1378,7 +1376,7 @@ Coll_Ctrl::add_hwcstring (const char *string, char **warnmsg)
   char *emsg;
   char *wmsg;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (hwcprof_default == 0)
     {
       /* Copy the counters already defined */
@@ -1472,14 +1470,12 @@ Coll_Ctrl::add_default_hwcstring (const char *resolution, char **warnmsg, bool a
     }
   /* allocate return string */
   int retsize = 2 * len + 10;
-  char *ret = (char *) malloc (retsize);
-  if (ret == NULL)
-    return strdup (GTXT ("internal error formating HW counter set; malloc failed\n"));
+  char *ret = (char *) xmalloc (retsize);
   *ret = 0;
   char *retp = ret;
   char *stringp = def_string;
   int first = 1;
-  char *hwc_defaultx = strdup (def_string);
+  char *hwc_defaultx = xstrdup (def_string);
 
   /* now massage the string in order to insert resolution for each counter */
   for (;;)
@@ -1608,7 +1604,7 @@ Coll_Ctrl::set_sample_period (const char *string)
 {
   int val;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strcmp (string, "on") == 0)
     val = 1;
   else if (strcmp (string, "off") == 0)
@@ -1638,7 +1634,7 @@ char *
 Coll_Ctrl::set_size_limit (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strlen (string) == 0
       || strcmp (string, "unlimited") == 0 || strcmp (string, "none") == 0)
     {
@@ -1776,7 +1772,7 @@ Coll_Ctrl::join_group ()
          if (uinterrupt == 1)
            {
              close (groupfd);
-             return strdup (GTXT ("user interrupt\n"));
+             return xstrdup (GTXT ("user interrupt\n"));
            }
          // it's opened, now lock it
          if (fcntl (groupfd, F_SETLK, &flockbuf) != -1)
@@ -1820,7 +1816,7 @@ Coll_Ctrl::join_group ()
              // can't get the lock, close the file and try again
              close (groupfd);
              if (uinterrupt == 1)
-               return strdup (GTXT ("user interrupt\n"));
+               return xstrdup (GTXT ("user interrupt\n"));
              if (tries == 11900)
                return dbe_sprintf (GTXT ("Timed out: waiting for group file %s\n"), group_file);
 #if 0
@@ -1883,7 +1879,7 @@ Coll_Ctrl::set_directory (char *dir, char **warn)
   struct stat statbuf;
   *warn = NULL;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (stat (dir, &statbuf) != 0)
     return dbe_sprintf (GTXT ("Can't set directory `%s': %s\n"),
                        dir, strerror (errno));
@@ -1891,7 +1887,7 @@ Coll_Ctrl::set_directory (char *dir, char **warn)
     return dbe_sprintf (GTXT ("Can't set directory `%s': %s\n"),
                        dir, strerror (ENOTDIR));
   free (udir_name);
-  udir_name = strdup (dir);
+  udir_name = xstrdup (dir);
 
   // Process new setting
   *warn = preprocess_names ();
@@ -1922,14 +1918,14 @@ Coll_Ctrl::set_target (char* targetname)
   free (target_name);
   target_name = NULL;
   if (targetname != NULL)
-    target_name = strdup (targetname);
+    target_name = xstrdup (targetname);
   return 0;
 }
 
 void
 Coll_Ctrl::set_default_stem (const char* stem)
 {
-  default_stem = strdup (stem);
+  default_stem = xstrdup (stem);
   preprocess_names ();
   (void) update_expt_name (false, false); // no warnings
 }
@@ -1944,7 +1940,7 @@ Coll_Ctrl::set_expt (const char *ename, char **warn, bool overwriteExp)
       uexpt_name = NULL;
       return NULL;
     }
-  char *exptname = canonical_path (strdup (ename));
+  char *exptname = canonical_path (xstrdup (ename));
   size_t i = strlen (exptname);
   if (i < 4 || strcmp (&exptname[i - 3], ".er") != 0)
     {
@@ -1980,7 +1976,7 @@ char *
 Coll_Ctrl::set_group (char *groupname)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (expt_group != NULL)
     {
       free (expt_group);
@@ -1996,7 +1992,7 @@ Coll_Ctrl::set_group (char *groupname)
   int i = (int) strlen (groupname);
   if (i < 5 || strcmp (&groupname[i - 4], ".erg") != 0)
     return dbe_sprintf (GTXT ("Experiment group name `%s'must end in `.erg'\n"), groupname);
-  expt_group = strdup (groupname);
+  expt_group = xstrdup (groupname);
   preprocess_names ();
   (void) update_expt_name (true, false);
   return NULL;
@@ -2007,7 +2003,7 @@ Coll_Ctrl::set_java_mode (const char *string)
 {
   struct stat statbuf;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strlen (string) == 0 || strcmp (string, "on") == 0)
     {
 #if defined(GPROFNG_JAVA_PROFILING)
@@ -2024,7 +2020,7 @@ Coll_Ctrl::set_java_mode (const char *string)
        }
       return NULL;
 #else
-      return strdup (GTXT ("gprofng was built without support for profiling Java applications\n"));
+      return xstrdup (GTXT ("gprofng was built without support for profiling Java applications\n"));
 #endif
     }
   if (strcmp (string, "off") == 0)
@@ -2071,9 +2067,9 @@ char *
 Coll_Ctrl::set_java_path (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   free (java_path);
-  java_path = strdup (string);
+  java_path = xstrdup (string);
   return NULL;
 }
 
@@ -2082,12 +2078,12 @@ Coll_Ctrl::set_java_args (char *string)
 {
   char *next;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   char *prev_java_args = java_args;
   if (string == NULL || strlen (string) == 0)
-    java_args = strdup ("");
+    java_args = xstrdup ("");
   else
-    java_args = strdup (string);
+    java_args = xstrdup (string);
   // now count the number of Java arguments
   for (next = java_args; *next; next++)
     {
@@ -2116,7 +2112,7 @@ char *
 Coll_Ctrl::set_follow_mode (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   free (follow_spec_usr);
   free (follow_spec_cmp);
   follow_spec_usr = NULL;
@@ -2143,18 +2139,13 @@ Coll_Ctrl::set_follow_mode (const char *string)
       int ercode;
       const char *userspec = &string[1];
       size_t newstrlen = strlen (userspec) + 3;
-      char * str = (char *) malloc (newstrlen);
-      if (str)
-       {
-         snprintf (str, newstrlen, "^%s$", userspec);
-         assert (strlen (str) == newstrlen - 1);
-         ercode = regcomp (&regex_desc, str, REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
-       }
-      else
-       ercode = 1;
+      char * str = (char *) xmalloc (newstrlen);
+      snprintf (str, newstrlen, "^%s$", userspec);
+      assert (strlen (str) == newstrlen - 1);
+      ercode = regcomp (&regex_desc, str, REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
       if (!ercode)
        {
-         follow_spec_usr = strdup (string);
+         follow_spec_usr = xstrdup (string);
          /* Ideally, follow_spec_cmp = [serialized regex_desc], */
          /* so that libcollector wouldn't have to recompile it. */
          /* For now, just copy the regular expression into follow_spec_cmp */
@@ -2173,7 +2164,7 @@ char *
 Coll_Ctrl::set_prof_idle (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strlen (string) == 0 || strcmp (string, "on") == 0)
     {
       prof_idle = 1;
@@ -2191,7 +2182,7 @@ char *
 Coll_Ctrl::set_archive_mode (const char *string)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (string == NULL || strlen (string) == 0)
     string = "on";
   if (strcasecmp (string, "on") == 0 || strcasecmp (string, "off") == 0
@@ -2201,7 +2192,7 @@ Coll_Ctrl::set_archive_mode (const char *string)
       || strcasecmp (string, "all") == 0)
     {
       free (archive_mode);
-      archive_mode = strdup (string);
+      archive_mode = xstrdup (string);
       return NULL;
     }
   return dbe_sprintf (GTXT ("Unrecognized archive-mode parameter `%s'\n"), string);
@@ -2212,7 +2203,7 @@ Coll_Ctrl::set_sample_signal (int value)
 {
   const char *buf;
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (value == 0)
     {
       sample_sig = 0;
@@ -2241,9 +2232,7 @@ Coll_Ctrl::find_sig (const char *string)
   if (strncmp (string, "SIG", 3) != 0)
     {
       // no: add it
-      signame_alloc = (char *) malloc (strlen (string) + 3 + 1);
-      if (signame_alloc == NULL)
-       return -1;
+      signame_alloc = (char *) xmalloc (strlen (string) + 3 + 1);
       strcpy (signame_alloc, "SIG");
       strcpy (&signame_alloc[3], string);
       signame = signame_alloc;
@@ -2266,7 +2255,7 @@ char *
 Coll_Ctrl::set_pauseresume_signal (int value, int resume)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   if (value == 0)
     {
       pauseresume_sig = 0;
@@ -2299,7 +2288,7 @@ char *
 Coll_Ctrl::set_debug_mode (int value)
 {
   if (opened == 1)
-    return strdup (GTXT ("Experiment is active; command ignored.\n"));
+    return xstrdup (GTXT ("Experiment is active; command ignored.\n"));
   debug_mode = value;
   return NULL;
 }
@@ -2373,7 +2362,7 @@ Coll_Ctrl::preprocess_names ()
     }
   expno = 1;
   if (uexpt_name != NULL)
-    expt_name = strdup (uexpt_name);
+    expt_name = xstrdup (uexpt_name);
   else
     {
       // no user name -- pick a default
@@ -2382,12 +2371,12 @@ Coll_Ctrl::preprocess_names ()
       char *stembase;
       if (expt_group == NULL)
        {
-         stem = strdup (default_stem);
+         stem = xstrdup (default_stem);
          stembase = stem;
        }
       else
        {
-         stem = strdup (expt_group);
+         stem = xstrdup (expt_group);
          stem[strlen (stem) - 4] = 0;
          stembase = stem;
          // now remove any leading directory
@@ -2401,7 +2390,7 @@ Coll_Ctrl::preprocess_names ()
          if (strlen (stembase) == 0)
            {
              free (stem);
-             stem = strdup (default_stem);
+             stem = xstrdup (default_stem);
              stembase = stem;
            }
        }
@@ -2417,35 +2406,35 @@ Coll_Ctrl::preprocess_names ()
   char *s = strrchr (expt_name, '/');
   if (s == NULL)
     {
-      expt_dir = strdup (".");
-      base_name = strdup (expt_name);
+      expt_dir = xstrdup (".");
+      base_name = xstrdup (expt_name);
     }
   else
     {
       expt_dir = dbe_strndup (expt_name, s - expt_name);
-      base_name = strdup (s + 1);
+      base_name = xstrdup (s + 1);
     }
 
   if (expt_dir[0] == '/')
-    store_dir = strdup (expt_dir);
+    store_dir = xstrdup (expt_dir);
   else if ((udir_name == NULL) || (udir_name[0] == 0))
     {
       if (expt_dir[0] == 0)
-       store_dir = strdup (".");
+       store_dir = xstrdup (".");
       else
-       store_dir = strdup (expt_dir);
+       store_dir = xstrdup (expt_dir);
     }
   else
     {
       /* udir_name is a non-empty string */
       if (expt_dir[0] == 0)
-       store_dir = strdup (udir_name);
+       store_dir = xstrdup (udir_name);
       else
        store_dir = dbe_sprintf ("%s/%s", udir_name, expt_dir);
     }
   free (store_ptr);
   if (strcmp (store_dir, ".") == 0)
-    store_ptr = strdup (base_name);
+    store_ptr = xstrdup (base_name);
   else
     store_ptr = dbe_sprintf ("%s/%s", store_dir, base_name);
 
@@ -2453,7 +2442,7 @@ Coll_Ctrl::preprocess_names ()
   if (strcmp (store_dir, prev_store_dir) != 0)
     {
       free (prev_store_dir);
-      prev_store_dir = strdup (store_dir);
+      prev_store_dir = xstrdup (store_dir);
       const char *fstype = get_fstype (store_dir);
       if (interactive && enabled && (fstype != NULL) && (nofswarn == 0))
        sb.appendf (GTXT ("Experiment directory is set to a file system of type \"%s\",\n"
@@ -2513,7 +2502,7 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname)
     return NULL;
 
   // save the name for a changed message
-  char *oldbase = strdup (base_name);
+  char *oldbase = xstrdup (base_name);
 
   // the name is of the from prefix.nnn.er; extract the value of nnn
   int version = atoi (&base_name[pcount + 1]);
@@ -2568,17 +2557,17 @@ Coll_Ctrl::update_expt_name (bool chgmsg, bool chkonly, bool newname)
   else
     free (oldbase);
   free (base_name);
-  base_name = strdup (newbase);
+  base_name = xstrdup (newbase);
 
   // now, reset expt_name to reflect new setting
   free (expt_name);
   if (expt_dir[0] == 0)
-    expt_name = strdup (base_name);
+    expt_name = xstrdup (base_name);
   else
     expt_name = dbe_sprintf ("%s/%s", expt_dir, base_name);
   free (store_ptr);
   if (strcmp (store_dir, ".") == 0)
-    store_ptr = strdup (base_name);
+    store_ptr = xstrdup (base_name);
   else
     store_ptr = dbe_sprintf ("%s/%s", store_dir, base_name);
   closedir (dir);
@@ -2712,7 +2701,7 @@ Coll_Ctrl::find_signal_name (int signal)
   char *str_signal = NULL;
   const char *buf = strsignal (signal);
   if (buf != NULL)
-    str_signal = strdup (buf);
+    str_signal = xstrdup (buf);
   return str_signal;
 }
 
@@ -2729,7 +2718,7 @@ Coll_Ctrl::get (char * control)
     {
       if ((size_limit > 0))
        return dbe_sprintf ("%d", size_limit);
-      return strdup (ipc_str_unlimited);
+      return xstrdup (ipc_str_unlimited);
     }
   if (!strncmp (control, ipc_str_time_limit, len))
     {
@@ -2743,67 +2732,67 @@ Coll_Ctrl::get (char * control)
            }
          return dbe_sprintf ("0s-%ds", time_run);
        }
-      return strdup (ipc_str_unlimited);
+      return xstrdup (ipc_str_unlimited);
     }
   if (strncmp (control, ipc_str_arch_exp, len) == 0)
-    return strdup (get_archive_mode ());
+    return xstrdup (get_archive_mode ());
   if (!strncmp (control, ipc_str_descendant, len))
     {
       switch (get_follow_mode ())
        {
        case FOLLOW_ON:
-         return strdup (ipc_str_on);
+         return xstrdup (ipc_str_on);
        case FOLLOW_ALL:
-         return strdup (ipc_str_on);
+         return xstrdup (ipc_str_on);
        case FOLLOW_NONE:
        default:
-         return strdup (ipc_str_off);
+         return xstrdup (ipc_str_off);
        }
     }
   if (!strncmp (control, ipc_str_prof_idle, len))
     {
       if (prof_idle == 0)
-       return strdup (ipc_str_off);
-      return strdup (ipc_str_on);
+       return xstrdup (ipc_str_off);
+      return xstrdup (ipc_str_on);
     }
   if (!strncmp (control, ipc_str_clkprof, len))
     {
       if (clkprof_default == 1 && clkprof_enabled == 1) // Default value
-       return strdup (ipc_str_empty);
+       return xstrdup (ipc_str_empty);
       if (clkprof_enabled == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       if ((clkprof_timer > 0))
        return dbe_sprintf ("%d", clkprof_timer / 1000);
-      return strdup (ipc_str_internal_error);
+      return xstrdup (ipc_str_internal_error);
     }
   if (!strncmp (control, ipc_str_hwcprof, len))
     {
       if (hwcprof_enabled_cnt == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       if (hwc_string != NULL)
        return dbe_sprintf ("on\n%s", hwc_string);
-      return strdup (ipc_str_on); // XXX need more details?
+      return xstrdup (ipc_str_on); // XXX need more details?
     }
   if (!strncmp (control, ipc_str_javaprof, len))
     {
       if (java_mode == 0)
-       return strdup (ipc_str_off);
-      return strdup (ipc_str_on);
+       return xstrdup (ipc_str_off);
+      return xstrdup (ipc_str_on);
     }
   if (!strncmp (control, ipc_str_sample, len))
     {
       if (sample_default == 1 && sample_period == 1) // Default value
-       return strdup (ipc_str_empty);
+       return xstrdup (ipc_str_empty);
       if (sample_period == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       if (sample_period > 0)
        return dbe_sprintf ("%d", sample_period);
-      return strdup (ipc_str_internal_error);
+      return xstrdup (ipc_str_internal_error);
     }
   if (!strncmp (control, ipc_str_sample_sig, len))
     {
       if (sample_sig == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       char *str_signal = find_signal_name (sample_sig);
       if (str_signal != NULL)
        return str_signal;
@@ -2812,7 +2801,7 @@ Coll_Ctrl::get (char * control)
   if (!strncmp (control, ipc_str_pause_resume_sig, len))
     {
       if (pauseresume_sig == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       char *str_signal = find_signal_name (pauseresume_sig);
       if (str_signal != NULL)
        return str_signal;
@@ -2821,34 +2810,34 @@ Coll_Ctrl::get (char * control)
   if (!strncmp (control, ipc_str_synctrace, len))
     {
       if (synctrace_enabled == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       if (synctrace_thresh < 0)
-       return strdup ("on\nthreshold: calibrate");
+       return xstrdup ("on\nthreshold: calibrate");
       if (synctrace_thresh == 0)
-       return strdup ("on\nthreshold: all");
+       return xstrdup ("on\nthreshold: all");
       return dbe_sprintf ("on\nthreshold: %d", synctrace_thresh);
     }
   if (!strncmp (control, ipc_str_heaptrace, len))
     {
       if (heaptrace_mode == NULL)
-       return strdup (ipc_str_off);
-      return strdup (ipc_str_on);
+       return xstrdup (ipc_str_off);
+      return xstrdup (ipc_str_on);
     }
   if (!strncmp (control, ipc_str_iotrace, len))
     {
       if (iotrace_enabled == 0)
-       return strdup (ipc_str_off);
-      return strdup (ipc_str_on);
+       return xstrdup (ipc_str_off);
+      return xstrdup (ipc_str_on);
     }
   if (!strncmp (control, ipc_str_count, len))
     {
       if (count_enabled == 0)
-       return strdup (ipc_str_off);
+       return xstrdup (ipc_str_off);
       if (count_enabled < 0)
-       return strdup ("on\nstatic");
-      return strdup (ipc_str_on);
+       return xstrdup ("on\nstatic");
+      return xstrdup (ipc_str_on);
     }
-  return strdup (ipc_str_unknown_control);
+  return xstrdup (ipc_str_unknown_control);
 }
 
 /**
@@ -2914,7 +2903,7 @@ Coll_Ctrl::set (char * control, const char * value)
     return set_sample_signal (find_sig (value));
   if (!strncmp (control, ipc_str_pause_resume_sig, len))
     {
-      char *str_signal = strdup (value);
+      char *str_signal = xstrdup (value);
       char *str_state = strchr (str_signal, (int) '\n');
       if (str_state != NULL)
        {
@@ -2936,7 +2925,7 @@ Coll_Ctrl::set (char * control, const char * value)
     return set_iotrace (value);
   if (!strncmp (control, ipc_str_count, len))
     return set_count (value);
-  return strdup (ipc_str_unknown_control);
+  return xstrdup (ipc_str_unknown_control);
 }
 
 /**
@@ -2957,7 +2946,7 @@ Coll_Ctrl::unset (char * control)
     }
   if (!strncmp (control, ipc_str_arch_exp, len))
     {
-      archive_mode = strdup ("on");
+      archive_mode = xstrdup ("on");
       return NULL;
     }
   if (!strncmp (control, ipc_str_descendant, len))
@@ -3031,12 +3020,12 @@ Coll_Ctrl::unset (char * control)
       Nflag = 0;
       return NULL;
     }
-  return strdup (ipc_str_unknown_control);
+  return xstrdup (ipc_str_unknown_control);
 }
 
 void
 Coll_Ctrl::set_project_home (char *s)
 {
   if (s)
-    project_home = strdup (s);
+    project_home = xstrdup (s);
 }
index 79d14eb22cc1390713ea003be6d13deb1c97769e..636bcf36705ba505baee42b084a349e0bc9976c4 100644 (file)
@@ -25,6 +25,7 @@
 #include <values.h>
 #include <assert.h>
 
+#include "libiberty.h"
 #include "comp_com.h"
 
 /*
@@ -839,9 +840,7 @@ ccm_vis_init ()
     return;
   done = 1;
   size = ccm_vis_index ((COMPMSG_ID) (CCMV_BASIC << 8));
-  ccm_attrs = (Ccm_Attr_t *) calloc (size, sizeof (Ccm_Attr_t));
-  if (ccm_attrs == NULL)
-    exit (1);
+  ccm_attrs = (Ccm_Attr_t *) xcalloc (size, sizeof (Ccm_Attr_t));
   vindex = ccm_vis_index (CCM_MODDATE);
   ccm_attrs[vindex].vis = CCMV_VER | CCMV_BASIC | CCMV_UNIMPL;
   ccm_attrs[vindex].name = "CCM_MODDATE";
index 41fa092c0975f838e0d1982306cddd8c3ac27755..42f990e0e12ea37b332e08ffba5167d50b9d35e2 100644 (file)
@@ -33,6 +33,7 @@
 #include <collctrl.h>
 #include <StringBuilder.h>
 #include "collect.h"
+#include "libiberty.h"
 
 /* get_count_data -- format exec of bit to do the real work */
 void
@@ -44,7 +45,7 @@ collect::get_count_data ()
 
   // reserve space for original args, plus 30 arguments to bit
   nargs = origargc + 30;
-  char **narglist = (char **) calloc (nargs, sizeof (char *));
+  char **narglist = (char **) xcalloc (nargs, sizeof (char *));
   arglist = narglist;
 
   // construct the command for bit
@@ -57,7 +58,7 @@ collect::get_count_data ()
       if (stat (command, &statbuf) == -1)
        {
          // if bit command does not exist there
-         char *first_look = strdup (command);
+         char *first_look = xstrdup (command);
          snprintf (command, sizeof (command), NTXT ("%s"), run_dir);
          s = strstr (command, NTXT ("/bin"));
          snprintf (s, sizeof (command) - (s - command), NTXT ("/prod/bin/bit"));
@@ -69,7 +70,7 @@ collect::get_count_data ()
            }
          free (first_look);
        }
-      *arglist++ = strdup (command);
+      *arglist++ = xstrdup (command);
     }
   else
     {
index 951ebaf747946434926bed18aa4be8d0d4f47836..c303ac8dc4177867a590ed66dc943401c2c9b590 100644 (file)
 #include <stdio.h>
 #include <stdarg.h>
 
+#include "libiberty.h"
 #include "i18n.h"
 
+#define malloc(s) xmalloc (s)
+#define realloc(p, s) xrealloc (p, s)
+#define calloc(n, s) xcalloc (n, s)
+#define strdup(s) xstrdup (s)
+
 #define HWC_TRACELEVEL -1
 #if HWC_TRACELEVEL < 0
 #define TprintfT(x1,...)
diff --git a/gprofng/src/dbe_memmgr.c b/gprofng/src/dbe_memmgr.c
deleted file mode 100644 (file)
index 8c451cf..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/* Copyright (C) 2021-2024 Free Software Foundation, Inc.
-   Contributed by Oracle.
-
-   This file is part of GNU Binutils.
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 3, or (at your option)
-   any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, 51 Franklin Street - Fifth Floor, Boston,
-   MA 02110-1301, USA.  */
-
-#include "config.h"
-#include <dlfcn.h>
-#include "util.h"
-
-#define CHECK_OUT_OF_MEM(ptr, size) if (ptr == NULL) err_out_of_memory(size)
-
-/* Report Out of Memory error and exit */
-static void
-err_out_of_memory (unsigned nbytes)
-{
-  char *nm = get_prog_name (1);
-  if (nm)
-    fprintf (stderr, GTXT ("%s: Error: Memory capacity exceeded.\n"), nm);
-  else
-    fprintf (stderr, GTXT ("Error: Memory capacity exceeded.\n"));
-  fprintf (stderr, GTXT ("  Requested %u bytes.\n"), nbytes);
-  exit (16);
-}
-
-#define CALL_REAL(x) (__real_##x)
-#define NULL_PTR(x) ( __real_##x == NULL )
-
-static void *(*__real_malloc)(size_t) = NULL;
-static void (*__real_free)(void *) = NULL;
-static void *(*__real_realloc)(void *, size_t) = NULL;
-static void *(*__real_calloc)(size_t, size_t) = NULL;
-static char *(*__real_strdup)(const char*) = NULL;
-static volatile int in_init = 0;
-
-static int
-init_heap_intf ()
-{
-  in_init = 1;
-  __real_malloc = (void*(*)(size_t))dlsym (RTLD_NEXT, "malloc");
-  __real_free = (void(*)(void *))dlsym (RTLD_NEXT, "free");
-  __real_realloc = (void*(*)(void *, size_t))dlsym (RTLD_NEXT, "realloc");
-  __real_calloc = (void*(*)(size_t, size_t))dlsym (RTLD_NEXT, "calloc");
-  __real_strdup = (char*(*)(const char*))dlsym (RTLD_NEXT, "strdup");
-  in_init = 0;
-  return 0;
-}
-
-/* --------------------------------------------------------------------------- */
-/* libc's memory management functions substitutions */
-
-/* Allocate memory and make sure we got some */
-void *
-malloc (size_t size)
-{
-  if (NULL_PTR (malloc))
-    init_heap_intf ();
-  void *ptr = CALL_REAL (malloc)(size);
-  CHECK_OUT_OF_MEM (ptr, size);
-  return ptr;
-}
-
-
-/* Implement a workaround for a libdl recursion problem */
-void *
-calloc (size_t nelem, size_t size)
-{
-  if (NULL_PTR (calloc))
-    {
-      /* If a program is linked with libpthread then the following
-       * calling sequence occurs:
-       * init_heap_intf -> dlsym -> calloc -> malloc -> init_heap_intf
-       * We break some performance improvement in libdl by returning
-       * NULL but preserve functionality.
-       */
-      if (in_init)
-       return NULL;
-      init_heap_intf ();
-    }
-  return CALL_REAL (calloc)(nelem, size);
-}
-
-/* Free the storage associated with data */
-void
-free (void *ptr)
-{
-  if (ptr == NULL)
-    return;
-  if (NULL_PTR (free))
-    init_heap_intf ();
-  CALL_REAL (free)(ptr);
-  return;
-}
-
-/* Reallocate buffer */
-void *
-realloc (void *ptr, size_t size)
-{
-  if (NULL_PTR (realloc))
-    init_heap_intf ();
-  ptr = CALL_REAL (realloc)(ptr, size);
-  CHECK_OUT_OF_MEM (ptr, size);
-  return ptr;
-}
index 70510fbd4bda4fef70285bfc42051bcebd7c8953..b7d3d9da0efd514f741d518772da7d139d992dbd 100644 (file)
@@ -136,7 +136,7 @@ int
 collect::putenv_libcollector_ld_misc ()
 {
 #if 0 // XXX 1 turns on LD_DEBUG
-  putenv (strdup ("LD_DEBUG=audit,bindings,detail"));
+  putenv (xstrdup ("LD_DEBUG=audit,bindings,detail"));
 #endif
   // workaround to have the dynamic linker use absolute names
   if (add_env (dbe_strdup ("LD_ORIGIN=yes")))
@@ -156,7 +156,7 @@ collect::putenv_libcollector_ld_misc ()
   if (ev)
     { /* GPROFNG_PRELOAD_LIBDIRS is used only in the gprofng testing.
        * Use these directories first.  */
-      ev = strdup (ev);
+      ev = xstrdup (ev);
       for (char *s = ev; s;)
        {
          char *s1 = strchr (s, ':');
@@ -246,7 +246,7 @@ collect::add_ld_preload (const char *lib)
     {
       char *old_sp = sp_preload_list[ii];
       if (old_sp == NULL)
-       sp_preload_list[ii] = strdup (lib);
+       sp_preload_list[ii] = xstrdup (lib);
       else
        {
          sp_preload_list[ii] = dbe_sprintf ("%s %s", old_sp, lib);
index ff6816da6a20feb654842505e38327cc2099814d..00a44509f8ecaffe0020259ad0266fd438a4fb47 100644 (file)
@@ -528,7 +528,7 @@ er_archive::check_args (int argc, char *argv[])
          if (dseen)
            fprintf (stderr, GTXT ("Warning: option -d was specified several times. Last value is used.\n"));
          free (common_archive_dir);
-         common_archive_dir = strdup (optarg);
+         common_archive_dir = xstrdup (optarg);
          dseen = 1;
          break;
        case 'q':
@@ -546,7 +546,7 @@ er_archive::check_args (int argc, char *argv[])
          if (rseen)
            fprintf (stderr, GTXT ("Warning: option -r was specified several times. Last value is used.\n"));
          free (common_archive_dir);
-         common_archive_dir = strdup (optarg);
+         common_archive_dir = xstrdup (optarg);
          use_relative_path = 1;
          rseen = 1;
          break;
@@ -667,7 +667,7 @@ er_archive::check_env_var ()
     }
   if (opts->size () > 0)
     {
-      char **arr = (char **) malloc (sizeof (char *) *opts->size ());
+      char **arr = (char **) xmalloc (sizeof (char *) *opts->size ());
       for (long i = 0; i < opts->size (); i++)
        arr[i] = opts->get (i);
       if (-1 == check_args (opts->size (), arr))
@@ -697,5 +697,6 @@ real_main (int argc, char *argv[])
 int
 main (int argc, char *argv[])
 {
+  xmalloc_set_program_name (argv[0]);
   return catch_out_of_memory (real_main, argc, argv);
 }
index c80c1b0bbeee4f6572435d2c7023614fe0e3d99d..4bf9f077df9786663eb2f2b79aadaf7ece1b5cfb 100644 (file)
@@ -63,6 +63,7 @@ static Process **processes;
 int
 main (int argc, char *argv[])
 {
+  xmalloc_set_program_name (argv[0]);
   // disable any alarm that might be pending
   int r = alarm (0);
   if (r != 0)
index 24af375edf153e06090d9e9f9e2779ad1fb791c5..5d885b5b607c5d337ed01bc8b6866513deb06da3 100644 (file)
@@ -89,6 +89,7 @@ real_main (int argc, char *argv[])
 int
 main (int argc, char *argv[])
 {
+  xmalloc_set_program_name (argv[0]);
   return catch_out_of_memory (real_main, argc, argv);
 }
 
@@ -216,7 +217,7 @@ er_src::set_outfile (char *cmd, FILE *&set_file)
       else if ((fname = strstr (cmd, "~")) != NULL && home != NULL)
        cmdpath = dbe_sprintf ("/home/%s", fname + 1);
       else
-       cmdpath = strdup (cmd);
+       cmdpath = xstrdup (cmd);
       new_file = fopen (cmdpath, "w");
       if (new_file == NULL)
        {
@@ -666,7 +667,7 @@ er_src::open (char *exe)
   Vector<Histable*> *module_lst;
 
   // Construct the Segment structure
-  char *path = strdup (exe);
+  char *path = xstrdup (exe);
   lo = dbeSession->createLoadObject (path);
   if (NULL == lo->dbeFile->find_file (lo->dbeFile->get_name ()))
     {
index 3d7774a150ad3c4bc93d30e11742d14e71d7d465..ad60e76f3810cc65bd8406a8baa27c5c42129c9c 100644 (file)
@@ -112,6 +112,7 @@ reexec_enhance (int argc, char *argv[])
 int
 main (int argc, char *argv[])
 {
+  xmalloc_set_program_name (argv[0]);
   er_print *erprint;
   int ind = 1;
   if (argc > ind && *argv[ind] == '-')
@@ -533,7 +534,7 @@ er_print::process_object_select (char *names)
   if (!got_err)
     { // good coverage string
       free (cov_string);
-      cov_string = strdup (names);
+      cov_string = xstrdup (names);
     }
   else
     { // bad, restore original coverage
@@ -1662,9 +1663,9 @@ er_print::exp_list ()
   for (index = 0; index < size; index++)
     {
       lists[0][index] = dbe_sprintf (NTXT ("%d"), index + 1);
-      lists[1][index] = strdup (dbev->get_exp_enable (index) ? GTXT ("yes") : GTXT ("no"));
+      lists[1][index] = xstrdup (dbev->get_exp_enable (index) ? GTXT ("yes") : GTXT ("no"));
       lists[2][index] = dbe_sprintf (NTXT ("%d"), dbeSession->get_exp (index)->getPID ());
-      lists[3][index] = strdup (dbeSession->get_exp (index)->get_expt_name ());
+      lists[3][index] = xstrdup (dbeSession->get_exp (index)->get_expt_name ());
     }
   disp_list (4, size, align, header, lists);
   for (int i = 0; i < 4; i++)
@@ -1834,9 +1835,9 @@ er_print::seg_list ()
          continue;
       }
     bool expand = dbev->get_lo_expand (lo->seg_idx);
-    lists[0][new_index] = strdup (expand ? GTXT ("yes") : GTXT ("no"));
+    lists[0][new_index] = xstrdup (expand ? GTXT ("yes") : GTXT ("no"));
     lists[1][new_index] = dbe_sprintf (NTXT ("%lld"), (ll_t) lo->get_size ());
-    lists[2][new_index] = strdup (lo->get_pathname ());
+    lists[2][new_index] = xstrdup (lo->get_pathname ());
     new_index++;
   }
 
@@ -1903,7 +1904,7 @@ er_print::filter_list (CmdType cmd_type)
        continue;
       lists[0][new_index] = dbe_sprintf (NTXT ("%d"), index + 1);
       pattern = dbev->get_exp_enable (index) ? select->get_pattern () : NULL;
-      lists[1][new_index] = strdup (pattern && *pattern ? pattern : GTXT ("none"));
+      lists[1][new_index] = xstrdup (pattern && *pattern ? pattern : GTXT ("none"));
       lists[2][new_index] = dbe_sprintf (NTXT ("%lld"), (ll_t) select->nelem ());
       lists[3][new_index] = select->get_status ();
       new_index++;
@@ -2822,7 +2823,7 @@ er_print::set_outfile (char *cmd, FILE *&set_file, bool append)
       else if ((fname = strstr (cmd, NTXT ("~"))) != NULL && home != NULL)
        path = dbe_sprintf (NTXT ("/home/%s"), fname + 1);
       else
-       path = strdup (cmd);
+       path = xstrdup (cmd);
       new_file = fopen (path, append ? NTXT ("a") : NTXT ("w"));
       if (new_file == NULL)
        {
index a59fdb2af6d6ad99b9db9696ca122c2f6dc4ccd5..385b09771547f7cf9bd2818eb1f7b53894513ffb 100644 (file)
@@ -49,6 +49,7 @@ private:
 int
 main (int argc, char *argv[])
 {
+  xmalloc_set_program_name (argv[0]);
   Gprofng *gprofng = new Gprofng (argc, argv);
   gprofng->start();
   delete gprofng;
@@ -228,7 +229,7 @@ Gprofng::exec_cmd (char *tool_name, int argc, char **argv)
 
   const char *aname = app_names[first].app_name;
 
-  char **arr = (char **) malloc ((argc + 5) * sizeof (char *));
+  char **arr = (char **) xmalloc ((argc + 5) * sizeof (char *));
   char *pname = get_name ();
   char *exe_name = dbe_sprintf ("%.*s%s",
                        (int) (get_basename (pname) - pname), pname, aname);
index d5f377123ab7e456ba6b8c1ea1a4559920210d6f..3e706dbc9d078c50c70831c0d423ccc4cb52a208 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/wait.h>   // wait
 #include <locale.h>
 
+#include "libiberty.h"
 #include "DbeApplication.h"
 #include "Histable.h"
 #include "ipcio.h"
@@ -2686,7 +2687,7 @@ ipc_mainLoop (int argc, char *argv[])
   if (er_print_catch_crash)
     {
       /* reserve memory for fatal error processing */
-      fatalErrorDynamicMemory = (char *) malloc (4 * 1024 * 1024); // reserve 4 MB
+      fatalErrorDynamicMemory = (char *) xmalloc (4 * 1024 * 1024); // reserve 4 MB
       /* install a handler for SIGABRT */
       ipc_request_trace (TRACE_LVL_1, "Installing SIGABRT handler to send message to analyzer\n");
       sigemptyset (&act.sa_mask);
index 29d699dea545ae72248edd74a8d0d875161020fd..8ff16d5a8e2385790cb718262735c6dd60435cb5 100644 (file)
@@ -63,7 +63,7 @@ IPCrequest::IPCrequest (int sz, int reqID, int chID)
   channelID = chID;
   status = INITIALIZED;
   idx = 0;
-  buf = (char *) malloc (size);
+  buf = (char *) xmalloc (size);
   cancelImmediate = false;
 }
 
@@ -149,7 +149,7 @@ readSVal (IPCrequest *req)
       ipc_trace ("  readSVal: <NULL>\n");
       return NULL;
     }
-  char *str = (char *) malloc (len + 1);
+  char *str = (char *) xmalloc (len + 1);
   char *s = str;
   *s = (char) 0;
   while (len--)
index 228140b61ae268881bdeba915faaf860c62b9cca..e4919995db67f424b0d0716c1c2d8453199ff36a 100644 (file)
@@ -35,7 +35,7 @@
 #include "dbe_structs.h"
 #include "StringBuilder.h"
 #include "StringMap.h"      // For directory names
-#include "Application.h"    // Only for get_prog_name
+#include "Application.h"
 #include "vec.h"
 
 void
@@ -340,7 +340,7 @@ read_line (FILE *fptr)
 {
   // get an input line, no size limit
   int line_sz = 128; // starting size
-  char *line = (char *) malloc (line_sz);
+  char *line = (char *) xmalloc (line_sz);
 
   // read as much of the line as will fit in memory
   line[0] = 0;
@@ -353,7 +353,7 @@ read_line (FILE *fptr)
          if (len == 0 || line[len - 1] == '\n')
            break;
          // increase the buffer
-         char *lineNew = (char *) malloc (2 * line_sz);
+         char *lineNew = (char *) xmalloc (2 * line_sz);
          strncpy (lineNew, line, line_sz);
          lineNew[line_sz] = '\0';
          free (line);
@@ -531,7 +531,7 @@ parse_fname (char *in_str, char **fcontext)
   int ch = '`';
   if (in_str == NULL)
     return NULL;
-  char *copy = strdup (in_str);
+  char *copy = xstrdup (in_str);
   char *p = strchr (copy, ch);
   if (p != NULL)
     {
@@ -556,7 +556,7 @@ parse_fname (char *in_str, char **fcontext)
          return NULL;
        }
       free (*fcontext);
-      *fcontext = strdup (p);
+      *fcontext = xstrdup (p);
     }
   return copy;
 }
@@ -777,25 +777,12 @@ get_relative_link (const char *path_from, const char *path_to)
   return lname;
 }
 
-char *
-get_prog_name (int basename)
-{
-  char *nm = NULL;
-  if (theApplication)
-    {
-      nm = theApplication->get_name ();
-      if (nm && basename)
-       nm = get_basename (nm);
-    }
-  return nm;
-}
-
 char *
 dbe_strndup (const char *str, size_t len)
 {
   if (str == NULL)
     return NULL;
-  char *s = (char *) malloc (len + 1);
+  char *s = (char *) xmalloc (len + 1);
   strncpy (s, str, len);
   s[len] = '\0';
   return s;
@@ -815,11 +802,11 @@ dbe_sprintf (const char *fmt, ...)
     {
       if (buf_size <= 1)
        buffer[0] = 0;
-      return strdup (buffer);
+      return xstrdup (buffer);
     }
 
   va_start (vp, fmt);
-  char *buf = (char *) malloc (buf_size);
+  char *buf = (char *) xmalloc (buf_size);
   vsnprintf (buf, buf_size, fmt, vp);
   va_end (vp);
   return buf;
@@ -843,7 +830,7 @@ dbe_write (int f, const char *fmt, ...)
     }
 
   va_start (vp, fmt);
-  char *buf = (char *) malloc (buf_size);
+  char *buf = (char *) xmalloc (buf_size);
   vsnprintf (buf, buf_size, fmt, vp);
   va_end (vp);
   ssize_t val = write (f, buf, strlen (buf));
@@ -1064,35 +1051,32 @@ dbe_stat_internal (const char *path, dbe_stat_t *sbuf, bool file_only)
       if (theApplication->get_number_of_worker_threads () > 0)
        {
          struct worker_thread_info *wt_info;
-         wt_info = (worker_thread_info *) calloc (1, sizeof (worker_thread_info));
-         if (wt_info != NULL)
+         wt_info = (worker_thread_info *) xcalloc (1, sizeof (worker_thread_info));
+         int res = dbe_dispatch_on_thread (path, wt_info);
+         if (THREAD_FINISHED == res)
            {
-             int res = dbe_dispatch_on_thread (path, wt_info);
-             if (THREAD_FINISHED == res)
-               {
-                 int st = wt_info->result;
-                 extract_and_save_dirname (path, st);
-                 if (st == 0 && file_only)
-                   if (S_ISREG ((wt_info->statbuf).st_mode) == 0)
-                     st = -1; // It is not a regular file
-                 if (sbuf != NULL)
-                   *sbuf = wt_info->statbuf;
-                 free (wt_info);
-                 return st;
-               }
-             else
+             int st = wt_info->result;
+             extract_and_save_dirname (path, st);
+             if (st == 0 && file_only)
+               if (S_ISREG ((wt_info->statbuf).st_mode) == 0)
+                 st = -1; // It is not a regular file
+             if (sbuf != NULL)
+               *sbuf = wt_info->statbuf;
+             free (wt_info);
+             return st;
+           }
+         else
+           {
+             if (THREAD_CANCEL == res)
                {
-                 if (THREAD_CANCEL == res)
-                   {
-                     // Worker thread hung. Cannot free wt_info.
-                     // Allocated memory will be freed by worker thread.
-                     // save directory
-                     extract_and_save_dirname (path, 1);
-                     return 1; // stat64 failed
-                   }
-                 else  // THREAD_NOT_CREATED - continue on current thread
-                   free (wt_info);
+                 // Worker thread hung. Cannot free wt_info.
+                 // Allocated memory will be freed by worker thread.
+                 // save directory
+                 extract_and_save_dirname (path, 1);
+                 return 1; // stat64 failed
                }
+             else  // THREAD_NOT_CREATED - continue on current thread
+               free (wt_info);
            }
        }
     }
index cbbc2f7e118fca09849fbc97df04c0ece0da83d8..ca2480b30d402e4bbaf66e8ef18081cdf135412f 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/stat.h>
 #include <stdint.h>
 
+#include "libiberty.h"
 #include "gp-defs.h"
 #include "gp-time.h"
 #include "i18n.h"
@@ -105,7 +106,7 @@ get_basename (const char* name)
 inline char *
 dbe_strdup (const char *str)
 {
-  return str ? strdup (str) : NULL;
+  return str ? xstrdup (str) : NULL;
 }
 
 inline long
@@ -170,7 +171,6 @@ extern "C"
   char *canonical_path (char *path);
   char *get_relative_path (char *name);
   char *get_relative_link (const char *path_to, const char *path_from);
-  char *get_prog_name (int basename);
   char *dbe_strndup (const char *str, size_t len);
   int dbe_stat (const char *path, dbe_stat_t *sbuf);
   int dbe_stat_file (const char *path, dbe_stat_t *sbuf);
index 7d5be1f0b578f7fb465789f9aef26946cf361fa4..4ee4642d78ad76eb9d4c6a14e34241a85bce5c9a 100644 (file)
@@ -25,6 +25,7 @@
 #include <inttypes.h>
 #include <string.h>
 #include <stdlib.h>
+#include "libiberty.h"
 
 // This package implements a vector of items.
 
@@ -222,7 +223,7 @@ Vector<ITEM>::Vector (long sz)
 {
   count = 0;
   limit = sz > 0 ? sz : KILOCHUNK; // was 0;
-  data = limit ? (ITEM *) malloc (sizeof (ITEM) * limit) : NULL;
+  data = limit ? (ITEM *) xmalloc (sizeof (ITEM) * limit) : NULL;
   sorted = false;
 }
 
@@ -241,7 +242,7 @@ Vector<ITEM>
       else
        limit = limit * 2;
     }
-  data = (ITEM *) realloc (data, limit * sizeof (ITEM));
+  data = (ITEM *) xrealloc (data, limit * sizeof (ITEM));
 }
 
 template <typename ITEM> void
@@ -269,7 +270,7 @@ Vector<ITEM>::copy ()
   vector = new Vector<ITEM>;
   vector->count = count;
   vector->limit = limit;
-  vector->data = (ITEM *) malloc (sizeof (ITEM) * limit);
+  vector->data = (ITEM *) xmalloc (sizeof (ITEM) * limit);
   (void) memcpy ((char *) vector->data, (char *) data, sizeof (ITEM) * count);
   return vector;
 }