fix memory leak on PVStructure::removeField
This commit is contained in:
@@ -192,6 +192,7 @@ namespace epics { namespace pvData {
|
||||
}
|
||||
Structure *structure = const_cast<Structure *>(getStructure().get());
|
||||
structure->removeField(indRemove);
|
||||
delete origPVFields[indRemove];
|
||||
delete[] pImpl->pvFields;
|
||||
pImpl->pvFields = newPVFields;
|
||||
pImpl->numberFields = newLength;
|
||||
|
||||
@@ -2,9 +2,9 @@ TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
#PROD_HOST += temp
|
||||
#temp_SRCS += temp.cpp
|
||||
#temp_LIBS += pvData Com
|
||||
PROD_HOST += temp
|
||||
temp_SRCS += temp.cpp
|
||||
temp_LIBS += pvData Com
|
||||
|
||||
PROD_HOST += testPVAppend
|
||||
testPVAppend_SRCS += testPVAppend.cpp
|
||||
|
||||
@@ -35,11 +35,32 @@ static String alarmTimeStamp("alarm,timeStamp");
|
||||
static String alarmTimeStampValueAlarm("alarm,timeStamp,valueAlarm");
|
||||
static String allProperties("alarm,timeStamp,display,control,valueAlarm");
|
||||
|
||||
static void testAppendSimple(FILE * fd)
|
||||
{
|
||||
FieldConstPtrArray fields = new FieldConstPtr[0];
|
||||
PVStructure *pvParent = pvDataCreate->createPVStructure(
|
||||
0,String("request"),0,fields);
|
||||
PVString* pvStringField = static_cast<PVString*>(
|
||||
pvDataCreate->createPVScalar(pvParent, "fieldList", pvString));
|
||||
pvStringField->put(String("value,timeStamp"));
|
||||
pvParent->appendPVField(pvStringField);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
pvStringField = static_cast<PVString*>(
|
||||
pvDataCreate->createPVScalar(pvParent, "extra", pvString));
|
||||
pvStringField->put(String("junk"));
|
||||
pvParent->appendPVField(pvStringField);
|
||||
builder.clear();
|
||||
pvParent->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
delete pvParent;
|
||||
}
|
||||
|
||||
static void testAppendMore(FILE * fd)
|
||||
{
|
||||
PVStructure* pvStructure = pvDataCreate->createPVStructure(
|
||||
0,"top", 0);
|
||||
0,"parent", 0);
|
||||
PVStructure* pvChild1 = pvDataCreate->createPVStructure(
|
||||
pvStructure, "child1", 0);
|
||||
PVString *pvStringField = static_cast<PVString*>(
|
||||
@@ -57,8 +78,51 @@ static void testAppendMore(FILE * fd)
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
PVField *pvField = pvStructure->getSubField(String("child1.value"));
|
||||
pvField->message(String("test message"),infoMessage);
|
||||
delete pvStructure;
|
||||
}
|
||||
|
||||
static void append2(PVStructure* pvStructure,
|
||||
const char *oneName,const char *twoName,
|
||||
const char *oneValue,const char *twoValue)
|
||||
{
|
||||
PVField* array[2];
|
||||
PVString *pvStringField = static_cast<PVString*>(
|
||||
pvDataCreate->createPVScalar(0,oneName, pvString));
|
||||
pvStringField->put(oneValue);
|
||||
array[0] = pvStringField;
|
||||
pvStringField = static_cast<PVString*>(
|
||||
pvDataCreate->createPVScalar(0,twoName, pvString));
|
||||
pvStringField->put(twoValue);
|
||||
array[1] = pvStringField;
|
||||
pvStructure->appendPVFields(2,array);
|
||||
}
|
||||
static void testAppends(FILE * fd)
|
||||
{
|
||||
PVField** array = new PVField*[2];
|
||||
PVStructure* pvChild = pvDataCreate->createPVStructure(
|
||||
0, "child1", 0);
|
||||
append2(pvChild,"Joe","Mary","Good Guy","Good Girl");
|
||||
array[0] = pvChild;
|
||||
pvChild = pvDataCreate->createPVStructure(
|
||||
0, "child2", 0);
|
||||
append2(pvChild,"Bill","Jane","Bad Guy","Bad Girl");
|
||||
array[1] = pvChild;
|
||||
PVStructure* pvStructure = pvDataCreate->createPVStructure(
|
||||
0,"parent", 2,array);
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
PVField *pvField = pvStructure->getSubField("child2.Bill");
|
||||
assert(pvField!=0);
|
||||
bool ok = pvField->renameField("Joe");
|
||||
assert(ok);
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
pvField->getParent()->removePVField("Joe");
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
delete pvStructure;
|
||||
}
|
||||
|
||||
@@ -75,7 +139,9 @@ int main(int argc,char *argv[])
|
||||
standardField = getStandardField();
|
||||
standardPVField = getStandardPVField();
|
||||
convert = getConvert();
|
||||
testAppendMore(fd);
|
||||
//testAppendSimple(fd);
|
||||
//testAppendMore(fd);
|
||||
testAppends(fd);
|
||||
epicsExitCallAtExits();
|
||||
CDRMonitor::get().show(fd);
|
||||
return(0);
|
||||
|
||||
@@ -86,30 +86,31 @@ static void append2(PVStructure* pvStructure,
|
||||
const char *oneValue,const char *twoValue)
|
||||
{
|
||||
PVField* array[2];
|
||||
// make parent null to test setParent
|
||||
PVString *pvStringField = static_cast<PVString*>(
|
||||
pvDataCreate->createPVScalar(pvStructure,oneName, pvString));
|
||||
pvDataCreate->createPVScalar(0,oneName, pvString));
|
||||
pvStringField->put(oneValue);
|
||||
array[0] = pvStringField;
|
||||
pvStringField = static_cast<PVString*>(
|
||||
pvDataCreate->createPVScalar(pvStructure,twoName, pvString));
|
||||
pvDataCreate->createPVScalar(0,twoName, pvString));
|
||||
pvStringField->put(twoValue);
|
||||
array[1] = pvStringField;
|
||||
pvStructure->appendPVFields(2,array);
|
||||
}
|
||||
static void testAppends(FILE * fd)
|
||||
{
|
||||
PVField* array[2];
|
||||
PVStructure* pvStructure = pvDataCreate->createPVStructure(
|
||||
0,"parent", 0);
|
||||
PVField** array = new PVField*[2];
|
||||
// make parent null to test setParent
|
||||
PVStructure* pvChild = pvDataCreate->createPVStructure(
|
||||
pvStructure, "child1", 0);
|
||||
0, "child1", 0);
|
||||
append2(pvChild,"Joe","Mary","Good Guy","Good Girl");
|
||||
array[0] = pvChild;
|
||||
pvChild = pvDataCreate->createPVStructure(
|
||||
pvStructure, "child2", 0);
|
||||
0, "child2", 0);
|
||||
append2(pvChild,"Bill","Jane","Bad Guy","Bad Girl");
|
||||
array[1] = pvChild;
|
||||
pvStructure->appendPVFields(2,array);
|
||||
PVStructure* pvStructure = pvDataCreate->createPVStructure(
|
||||
0,"parent", 2,array);
|
||||
builder.clear();
|
||||
pvStructure->toString(&builder);
|
||||
fprintf(fd,"%s\n",builder.c_str());
|
||||
|
||||
Reference in New Issue
Block a user