Skip to content

Commit

Permalink
Merge pull request #413 from LLNL/mcm86-04sep24-valgrind-leaks
Browse files Browse the repository at this point in the history
Fix several small leaks found with valgrind on CZ
  • Loading branch information
markcmiller86 committed Sep 10, 2024
1 parent 9af504e commit fe43c4f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 26 deletions.
17 changes: 4 additions & 13 deletions src/hdf5_drv/silo_hdf5.c
Original file line number Diff line number Diff line change
Expand Up @@ -9381,7 +9381,6 @@ db_hdf5_PutCsgvar(DBfile *_dbfile, char const *vname, char const *meshname,

PROTECT {
db_ResetGlobalData_Csgmesh();
strcpy(_csgm._meshname, meshname);
db_ProcessOptlist(DB_CSGMESH, optlist);

/* Write variable arrays: vars[] */
Expand Down Expand Up @@ -9417,7 +9416,7 @@ db_hdf5_PutCsgvar(DBfile *_dbfile, char const *vname, char const *meshname,
m.datatype = datatype;
m.conserved = _csgm._conserved;
m.extensive = _csgm._extensive;
strcpy(m.meshname, OPT(_csgm._meshname));
strcpy(m.meshname, OPT(meshname));
strcpy(m.label, OPT(_csgm._label));
strcpy(m.units, OPT(_csgm._unit));
db_SetMissingValueForPut(m.missing_value, _csgm._missing_value);
Expand Down Expand Up @@ -10045,7 +10044,6 @@ db_hdf5_PutQuadmesh(DBfile *_dbfile, char const *name, char const * const *coord
int compressionFlags;
void const * const *coords = (void const * const *) _coords;

FREE(_qm._meshname);
memset(&_qm, 0, sizeof _qm);
memset(&m, 0, sizeof m);

Expand Down Expand Up @@ -10500,7 +10498,6 @@ db_hdf5_PutQuadvar(DBfile *_dbfile, char const *name, char const *meshname, int
}
}

FREE(_qm._meshname);
memset(&_qm, 0, sizeof _qm);
memset(&m, 0, sizeof m);

Expand All @@ -10514,7 +10511,6 @@ db_hdf5_PutQuadvar(DBfile *_dbfile, char const *name, char const *meshname, int
_qm._group_no = -1;
_qm._missing_value = DB_MISSING_VALUE_NOT_SET;
db_ProcessOptlist(DB_QUADMESH, optlist); /*yes, QUADMESH*/
_qm._meshname = STRDUP(meshname);
_qm._nzones = _qm._nnodes = 1; /*initial value only*/
for (nels=(ndims?1:0), i=0; i<ndims; i++) {
nels *= dims[i];
Expand Down Expand Up @@ -10588,7 +10584,7 @@ db_hdf5_PutQuadvar(DBfile *_dbfile, char const *name, char const *meshname, int
m.centering = centering;
strcpy(m.label, OPT(_qm._label));
strcpy(m.units, OPT(_qm._unit));
strcpy(m.meshid, OPT(_qm._meshname));
strcpy(m.meshid, OPT(meshname));
db_SetMissingValueForPut(m.missing_value, _qm._missing_value);

for (i=0; i<ndims; i++) {
Expand Down Expand Up @@ -10651,10 +10647,8 @@ db_hdf5_PutQuadvar(DBfile *_dbfile, char const *name, char const *meshname, int
MEMBER_S(str(m.region_pnames), region_pnames);
} OUTPUT(dbfile, DB_QUADVAR, name, &m);

FREE(_qm._meshname);
} CLEANUP {
FREE(_qm._meshname);
/*void*/
void;
} END_PROTECT;
return 0;
}
Expand Down Expand Up @@ -10920,7 +10914,6 @@ db_hdf5_PutUcdmesh(DBfile *_dbfile, char const *name, int ndims, char const * co
}

/* Set global options */
strcpy(_um._meshname, name);
_um._coord_sys = DB_OTHER;
_um._facetype = DB_RECTILINEAR;
_um._ndims = ndims;
Expand Down Expand Up @@ -11113,7 +11106,6 @@ db_hdf5_PutUcdsubmesh(DBfile *_dbfile, char const *name, char const *parentmesh,
H5Tclose(o);

/* Set global options */
strcpy(_um._meshname, name);
_um._coord_sys = DB_OTHER;
_um._facetype = DB_RECTILINEAR;
_um._ndims = m.ndims;
Expand Down Expand Up @@ -11510,7 +11502,6 @@ db_hdf5_PutUcdvar(DBfile *_dbfile, char const *name, char const *meshname, int n
_um._use_specmf = DB_OFF;
_um._group_no = -1;
_um._missing_value = DB_MISSING_VALUE_NOT_SET;
strcpy(_um._meshname, meshname);
db_ProcessOptlist(DB_UCDMESH, optlist); /*yes, UCDMESH*/

/* Prepare for possible compression of ucdvars */
Expand Down Expand Up @@ -11566,7 +11557,7 @@ db_hdf5_PutUcdvar(DBfile *_dbfile, char const *name, char const *meshname, int n
m.conserved = _um._conserved;
m.extensive = _um._extensive;
db_SetMissingValueForPut(m.missing_value, _um._missing_value);
strcpy(m.meshid, OPT(_um._meshname));
strcpy(m.meshid, OPT(meshname));
strcpy(m.label, OPT(_um._label));
strcpy(m.units, OPT(_um._unit));

Expand Down
8 changes: 0 additions & 8 deletions src/pdb_drv/silo_pdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -10513,8 +10513,6 @@ db_pdb_PutCsgmesh (DBfile *dbfile, char const *name, int ndims,
/*-------------------------------------------------------------
* Initialize global data, and process options.
*-------------------------------------------------------------*/
strcpy(_csgm._meshname, name);

db_InitCsg(dbfile, name, optlist);

obj = DBMakeObject(name, DB_CSGMESH, 34);
Expand Down Expand Up @@ -10929,8 +10927,6 @@ db_pdb_PutUcdmesh (DBfile *dbfile, char const *name, int ndims, char const * con
/*-------------------------------------------------------------
* Initialize global data, and process options.
*-------------------------------------------------------------*/
strcpy(_um._meshname, name);

db_InitUcd(dbfile, name, optlist, ndims, nnodes, nzones);

obj = DBMakeObject(name, DB_UCDMESH, 33);
Expand Down Expand Up @@ -11127,8 +11123,6 @@ db_pdb_PutUcdsubmesh (DBfile *dbfile, char const *name, char const *parentmesh,
* Now we can initialize global data, and process options.
*-------------------------------------------------------------*/

strcpy(_um._meshname, name);

db_InitUcd(dbfile, name, optlist, ndims, nnodes, nzones);

obj = DBMakeObject(name, DB_UCDMESH, 28);
Expand Down Expand Up @@ -12456,8 +12450,6 @@ db_InitQuad (DBfile *_dbfile, char const *meshname, DBoptlist const *optlist,
*--------------------------------------------------*/
_qm._nzones = nzones;
_qm._nnodes = nnodes;
FREE(_qm._meshname);
_qm._meshname = STRDUP(meshname);

for (i = 0; i < ndims; i++) {
_qm._dims[i] = dims[i];
Expand Down
9 changes: 7 additions & 2 deletions src/silo/silo.c
Original file line number Diff line number Diff line change
Expand Up @@ -12797,7 +12797,6 @@ db_ResetGlobalData_PointMesh (int ndims) {
INTERNAL int
db_ResetGlobalData_QuadMesh (int ndims) {

FREE(_qm._meshname);
memset(&_qm, 0, sizeof(_qm));

_qm._coord_sys = DB_OTHER;
Expand Down Expand Up @@ -13136,7 +13135,7 @@ db_StringListToStringArray(char const *strList, int *_n, char sep, int skipSepAt
char **retval;

/* handle null case */
if (!strList)
if (!strList || strList[0] == '\0')
{
if (_n && *_n < 0) *_n = 0;
return 0;
Expand All @@ -13160,6 +13159,12 @@ db_StringListToStringArray(char const *strList, int *_n, char sep, int skipSepAt
n = *_n;
}

if (n <= 0)
{
if (_n && *_n < 0) *_n = n;
return 0;
}

retval = (char**) calloc(n+add1, sizeof(char*));
for (i=0, l=(skipSepAtIndexZero&&strList[0]==sep)?1:0; i<n; i++)
{
Expand Down
3 changes: 0 additions & 3 deletions src/silo/silo_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,6 @@ struct _qm {
char *_unit;
char *_labels[3];
char *_units[3];
char *_meshname;
int _baseindex[3];
int _baseindex_set;
int _group_no;
Expand Down Expand Up @@ -612,7 +611,6 @@ struct _um {
char *_unit;
char *_labels[3];
char *_units[3];
char _meshname[256];
char _nm_dims[64];
char _nm_zones[64];
char _nm_alignz[64];
Expand Down Expand Up @@ -657,7 +655,6 @@ struct _csgm {
char *_unit;
char *_labels[3];
char *_units[3];
char _meshname[256];
char _nm_time[64];
char _nm_dtime[64];
char _nm_cycle[64];
Expand Down
1 change: 1 addition & 0 deletions tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,4 @@

db.SetDir("/")
toc = db.GetToc()
db.Close()
6 changes: 6 additions & 0 deletions tools/python/pydbfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@ static PyObject *DBfile_DBGetVar(PyObject *self, PyObject *args)
for (int i = 0; i < narr; i++)
{
if (i == 0 && strArr[i] && strArr[i][0] == '\0')
{
FREE(strArr[i]);
continue; // skip an empty first entry
}
if (i == (narr-1) && strArr[i] && strArr[i][0] == '\0')
{
FREE(strArr[i]);
continue; // skip an empty last entry
}
PyList_Append(tmp2, PyString_FromString(strArr[i]));
FREE(strArr[i]);
}
Expand Down

0 comments on commit fe43c4f

Please sign in to comment.