2015-07-02 5 views
1

Valgrind сообщает мне, что мое приложение записывается за пределами выделенной памяти. Что может быть причиной этого? Вывод выглядит следующим образом:Запись внешней выделенной памяти

==18307== 1 errors in context 3 of 5: 
==18307== Invalid write of size 8 
==18307== at 0x65A35F0: QDateTime::QDateTime() (in /usr/lib64/libQtCore.so.4.8.6) 
==18307== by 0xB752F5: ora::Patient::Patient(ora::Site*)(oraPatient.cxx:53) 
==18307== by 0xB359F2: main (main.cxx:32) 
==18307== Address 0x16b3b680 is 8 bytes after a block of size 328 alloc'd 
==18307== at 0x4C29118: operator new(unsigned long) (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so) 
==18307== by 0xB359E2: main (main.cxx:32) 

Все участники известны во время компиляции и нет динамического выделения больше происходит. Строка, указанная в oraPatient.cxx:53, является конструктором. sizeof(Patient) возвращает 328, который является точно размером, который выделяется как состояния valgrind.

В моем случае это всегда последние два члена этого класса. Поэтому, если я прокомментирую их, следующий будет QString и QDateTime. Вот почему я не думаю, что это имеет отношение к самому Qt.

Patient.h

#define SimpleProperty(member, _type) \ 
    public: \ 
    /** 
    * @brief Set member of type _type. 
    * @param _arg_##member Value to be set 
    * @see m_##member for a more detailed description 
    */ \ 
    Q_INVOKABLE void Set##member(_type _arg_##member) \ 
    { \ 
    m_##member = _arg_##member;\ 
    } \ 
    /** 
    * @brief Get member of type _type. 
    * @return Returns the value of ##member 
    * @see m_##member for a more detailed description 
    */ \ 
    Q_INVOKABLE _type Get##member() const\ 
    { \ 
    return m_##member;\ 
    } \ 
    protected: \ 
    _type m_##member; \ 

class Patient : public RTObject 
{ 
    Q_OBJECT 

public: 
    QString ProposeRootFolderName() const; 
    explicit Patient(ora::Site *parent = NULL); 
    virtual ~Patient(); 
    Patient(const ora::Patient & other); 
    bool operator==(const Patient &patient); 
    bool operator!=(const ora::Patient & patient); 
    Q_INVOKABLE virtual QString GetStringRepresentation(const bool compriseChildren = true) const; 
    Q_INVOKABLE virtual bool IsValid() const; 
    Q_INVOKABLE void SetSite(ora::Site * parent); 
    Q_INVOKABLE void SetParent(ora::Site * parent); 
    Q_INVOKABLE ora::Site * GetParent() const; 
    Q_INVOKABLE ora::Site * GetSite() const; 
    Q_INVOKABLE bool Serialize(QDataStream &stream) const; 
    Q_INVOKABLE void Deserialize(QDataStream &stream); 
    Q_INVOKABLE const QList<ora::Treatment *> & GetTreatments() const; 
    Q_INVOKABLE ora::Treatment * GetTreatment(const int treatmentIndex) const; 
    Q_INVOKABLE bool AppendTreatment(ora::Treatment * treatment); 
    Q_INVOKABLE bool InsertTreatment(ora::Treatment * treatment, const int index); 
    Q_INVOKABLE bool RemoveTreatment(const int treatmentIndex); 
    Q_INVOKABLE bool RemoveTreatment(ora::Treatment * treatment); 
    Q_INVOKABLE void ClearTreatments(); 
    Q_INVOKABLE QList<ora::StructureSet *> & GetStructureSets(); 
    Q_INVOKABLE ora::StructureSet * GetStructureSet(const int structureSetIdx) const; 
    Q_INVOKABLE bool AppendStructureSet(ora::StructureSet * structureSet); 
    Q_INVOKABLE bool InsertStructureSet(ora::StructureSet * structureSet, const int index); 
    Q_INVOKABLE bool RemoveStructureSet(const int structureSetIdx); 
    Q_INVOKABLE int RemoveStructureSet(ora::StructureSet * structureSet); 
    Q_INVOKABLE void ClearStructureSets(); 
    Q_INVOKABLE const QMap<QString, PatientSetup*> &GetPatientSetups() const; 
    Q_INVOKABLE PatientSetup *GetPatientSetup(const QString &patientSetupID) const; 
    Q_INVOKABLE bool InsertPatientSetup(const QString &patientSetupID, PatientSetup *patientSetup); 
    Q_INVOKABLE bool RemovePatientSetup(const QString &patientSetupID); 
    Q_INVOKABLE bool RemovePatientSetup(PatientSetup *patientSetup); 
    Q_INVOKABLE void ClearPatientSetups(); 
    Q_INVOKABLE const QList<ImagingProtocol *> &GetImagingProtocols() const; 
    Q_INVOKABLE const QList<TreatmentOperation *> &GetTreatmentOperations() const; 
    Q_INVOKABLE const QList<Reg23Configuration *> &GetRegistrationConfigurations() const; 
    Q_INVOKABLE ImagingProtocol *GetImagingProtocol(const int i) const; 
    Q_INVOKABLE TreatmentOperation *GetTreatmentOperation(const int i); 
    Q_INVOKABLE Reg23Configuration *GetRegistrationConfiguration(const int i); 
    Q_INVOKABLE TreatmentOperation *GetTreatmentOperation(const QString toId); 
    Q_INVOKABLE Reg23Configuration *GetRegistrationConfiguration(const QString rcId); 
    Q_INVOKABLE bool AppendImagingProtocol(ImagingProtocol *protocol); 
    Q_INVOKABLE bool AppendTreatmentOperation(TreatmentOperation *to); 
    Q_INVOKABLE bool AppendRegistrationConfiguration(Reg23Configuration *rc); 
    Q_INVOKABLE bool RemoveImagingProtocol(const int i); 
    Q_INVOKABLE bool RemoveTreatmentOperation(const int i); 
    Q_INVOKABLE bool RemoveRegistrationConfiguration(const int i); 
    Q_INVOKABLE bool RemoveImagingProtocol(ImagingProtocol *protocol); 
    Q_INVOKABLE bool RemoveTreatmentOperation(TreatmentOperation *to); 
    Q_INVOKABLE bool RemoveRegistrationConfiguration(Reg23Configuration *rc); 
    Q_INVOKABLE void ClearImagingProtocols(); 
    Q_INVOKABLE void ClearTreatmentOperations(); 
    Q_INVOKABLE void ClearRegistrationConfigurations(); 
    Q_INVOKABLE bool InsertImagingProtocol(ImagingProtocol *protocol, const int i); 
    Q_INVOKABLE bool InsertTreatmentOperation(TreatmentOperation *to, const int i); 
    Q_INVOKABLE bool InsertRegistrationConfiguration(Reg23Configuration *rc, const int i); 
    Q_INVOKABLE const QList<Study *> &GetStudies() const; 
    Q_INVOKABLE Study *GetStudy(const int i) const; 
    Q_INVOKABLE Study *GetStudy(const QString sid) const; 
    Q_INVOKABLE bool AppendStudy(Study *stud); 
    Q_INVOKABLE bool RemoveStudy(const int i); 
    Q_INVOKABLE bool RemoveStudy(Study *stud); 
    Q_INVOKABLE void ClearStudies(); 
    Q_INVOKABLE bool InsertStudy(Study *stud, const int i); 
protected: 
    Patient &operator=(const Patient&); 
    virtual void Initialize(); 
    ora::Site *m_Site; 
    QList<ora::Treatment*> m_Treatments; 
    QList<ora::StructureSet*> m_StructureSets; 
    QMap<QString, PatientSetup*> m_PatientSetups; 
    QList<ImagingProtocol*> m_ImagingProtocols; 
    QList<TreatmentOperation *> m_TreatmentOperations; 
    QList<Study*> m_Studies; 
    QList<Reg23Configuration *> m_RegistrationConfigurations; 
    SimpleProperty(FirstName, QString) 
    SimpleProperty(LastName, QString) 
    Q_PROPERTY(QString FirstName READ GetFirstName WRITE SetFirstName) 
    Q_PROPERTY(QString LastName READ GetLastName WRITE SetLastName) 
    SimpleProperty(PatientID, QString) 
    Q_PROPERTY(QString PatientID READ GetPatientID WRITE SetPatientID) 
    SimpleProperty(OtherPatientIDs, QString) 
    Q_PROPERTY(QString OtherPatientIDs READ GetOtherPatientIDs WRITE SetOtherPatientIDs) 
    SimpleProperty(BarCodeID, QString) 
    Q_PROPERTY(QString BarCodeID READ GetBarCodeID WRITE SetBarCodeID) 
    SimpleProperty(IssuerOfPatientID, QString) 
    Q_PROPERTY(QString IssuerOfPatientID READ GetIssuerOfPatientID WRITE SetIssuerOfPatientID) 
    SimpleProperty(BirthDate, QDate) 
    Q_PROPERTY(QDate BirthDate READ GetBirthDate WRITE SetBirthDate) 
    SimpleProperty(PatientSex, QString) 
    Q_PROPERTY(QString PatientSex READ GetPatientSex WRITE SetPatientSex) 
    SimpleProperty(BirthTime, QTime) 
    Q_PROPERTY(QTime BirthTime READ GetBirthTime WRITE SetBirthTime) 
    SimpleProperty(OtherPatientNames, QString) 
    Q_PROPERTY(QString OtherPatientNames READ GetOtherPatientNames WRITE SetOtherPatientNames) 
    SimpleProperty(EthnicGroup, QString) 
    Q_PROPERTY(QString EthnicGroup READ GetEthnicGroup WRITE SetEthnicGroup) 
    SimpleProperty(Comments, QString) 
    Q_PROPERTY(QString Comments READ GetComments WRITE SetComments) 
    SimpleProperty(PatientSpeciesDescription, QString) 
    Q_PROPERTY(QString PatientSpeciesDescription READ GetPatientSpeciesDescription WRITE SetPatientSpeciesDescription) 
    SimpleProperty(PatientSpeciesCodeSequence, QString) 
    Q_PROPERTY(QString PatientSpeciesCodeSequence READ GetPatientSpeciesCodeSequence WRITE SetPatientSpeciesCodeSequence) 
    SimpleProperty(ResponsiblePerson, QString) 
    Q_PROPERTY(QString ResponsiblePerson READ GetResponsiblePerson WRITE SetResponsiblePerson) 
    SimpleProperty(ResponsiblePersonRole, QString) 
    Q_PROPERTY(QString ResponsiblePersonRole READ GetResponsiblePersonRole WRITE SetResponsiblePersonRole) 
    SimpleProperty(ResponsibleOrganization, QString) 
    Q_PROPERTY(QString ResponsibleOrganization READ GetResponsibleOrganization WRITE SetResponsibleOrganization) 
    SimpleProperty(HospitalID, QString) 
    Q_PROPERTY(QString HospitalID READ GetHospitalID WRITE SetHospitalID) 
    SimpleProperty(PatientSize, qreal) 
    Q_PROPERTY(qreal PatientSize READ GetPatientSize WRITE SetPatientSize) 
    SimpleProperty(PatientWeight, qreal) 
    Q_PROPERTY(qreal PatientWeight READ GetPatientWeight WRITE SetPatientWeight) 
    SimpleProperty(Address, QStringList) 
    Q_PROPERTY(QStringList Address READ GetAddress WRITE SetAddress) 
    SimpleProperty(CountryOfResidence, QString) 
    Q_PROPERTY(QString CountryOfResidence READ GetCountryOfResidence WRITE SetCountryOfResidence) 
    SimpleProperty(TelephoneNumbers, QStringList) 
    Q_PROPERTY(QStringList TelephoneNumbers READ GetTelephoneNumbers WRITE SetTelephoneNumbers) 
    SimpleProperty(Station, QString) 
    Q_PROPERTY(QString Station READ GetStation WRITE SetStation) 
    SimpleProperty(BirthName, QString) 
    Q_PROPERTY(QString BirthName READ GetBirthName WRITE SetBirthName) 
    SimpleProperty(Occupation, QString) 
    Q_PROPERTY(QString Occupation READ GetOccupation WRITE SetOccupation) 
    SimpleProperty(SmokingStatus, QString) 
    Q_PROPERTY(QString SmokingStatus READ GetSmokingStatus WRITE SetSmokingStatus) 
    SimpleProperty(PregnancyStatus, QString) 
    Q_PROPERTY(QString PregnancyStatus READ GetPregnancyStatus WRITE SetPregnancyStatus) 
    SimpleProperty(Attendant, QString) 
    Q_PROPERTY(QString Attendant READ GetAttendant WRITE SetAttendant) 
    SimpleProperty(AttendanceDate, QDateTime) 
    Q_PROPERTY(QDateTime AttendanceDate READ GetAttendanceDate WRITE SetAttendanceDate) 
    SimpleProperty(AbsenceDate, QDateTime) 
    Q_PROPERTY(QDateTime AbsenceDate READ GetAbsenceDate WRITE SetAbsenceDate) 
    SimpleProperty(LastAttendanceDate, QDateTime) 
    Q_PROPERTY(QDateTime LastAttendanceDate READ GetLastAttendanceDate WRITE SetLastAttendanceDate) 

private: 

}; 
QDataStream &operator<<(QDataStream &out, const ora::Patient &patient); 
QDataStream &operator>>(QDataStream &in, ora::Patient &patient); 

} // namespace ora 

Q_DECLARE_METATYPE(ora::Patient) 

Patient.cxx

#include "oraPatient.h" 

namespace ora 
{ 

Patient::Patient(ora::Site *parent) : RTObject(parent) 
{ 
    Initialize(); 

    m_Site = parent; 
} 

bool Patient::operator==(const Patient &patient) 
{ 
    return true; 
} 


bool Patient::operator!=(const ora::Patient &patient) 
{ 
    return !(*this == patient); 
} 

} // namespace ora 

RTObject.cxx

#include "oraRTObject.h" 

// SORRY 
#include "oraCentralLoggingService.h" 

namespace ora 
{ 

RTObject::RTObject(QObject *parent) : QObject(parent) 
{ 
    qRegisterMetaTypeStreamOperators<ApprovalStatusType>("ora::RTObject::ApprovalStatusType"); 
    qRegisterMetaTypeStreamOperators<BeamTypeType>("ora::RTObject::BeamTypeType"); 
    qRegisterMetaTypeStreamOperators<PlanIntentType>("ora::RTObject::PlanIntentType"); 
    qRegisterMetaTypeStreamOperators<PlanRelationshipType>("ora::RTObject::PlanRelationshipType"); 
    qRegisterMetaTypeStreamOperators<PrimaryDosimeterUnitType>("ora::RTObject::PrimaryDosimeterUnitType"); 
    qRegisterMetaTypeStreamOperators<RadiationTypeType>("ora::RTObject::RadiationTypeType"); 
    qRegisterMetaTypeStreamOperators<RotationDirectionType>("ora::RTObject::RotationDirectionType"); 
    qRegisterMetaTypeStreamOperators<ScanModeType>("ora::RTObject::ScanModeType"); 
    qRegisterMetaTypeStreamOperators<TreatmentDeliveryTypeType>("ora::RTObject::TreatmentDeliveryTypeType"); 
    qRegisterMetaTypeStreamOperators<ModeType>("ora::RTObject::ModeType"); 
    qRegisterMetaTypeStreamOperators<RTObject::PatientPositionType>("ora::RTObject::PatientPositionType"); 
    qRegisterMetaTypeStreamOperators<RTObject::QStringStringMap>("ora::RTObject::QStringStringMap"); 

    m_StreamVersion = 0; 
    m_IsValid = true; 
} 

RTObject::RTObject(const RTObject &) 
{ 
    m_StreamVersion = 0; 
    m_IsValid = false; 
} 

RTObject::~RTObject() 
{ 
} 

} // namespace ora 

Создание пациента: new Patient();

+1

Можете ли вы вставить код valgrind? – Cheiron

+3

«Почему мой код, который я вам не покажу, имеет проблемы с памятью?» Спросите кого-нибудь, кто * может * видеть ваш код. – Angew

+0

Добавлен код. Недостающие вещи, надеюсь, не актуальны, иначе я могу опубликовать их также. – user1760653

ответ

0

Это было довольно глупо, что я сделал. Нужно просто не использовать #ifdef в библиотеке, которая не имеет того же значения в приложении, которое использует библиотеку. Это приводит к тому, что заголовок моих приложений отличается от компилятора чем тот же заголовок в библиотеке, который, конечно же, заставляет компилятор приложения вычислять неправильные адреса.

Смежные вопросы