Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PETKA: Fix memory leaks #2497

Merged
merged 4 commits into from Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions engines/petka/objects/heroes.cpp
Expand Up @@ -34,7 +34,8 @@

namespace Petka {

QObjectPetka::QObjectPetka() {
QObjectPetka::QObjectPetka()
: _walk(nullptr) {
_field7C = 1;
_reaction = nullptr;
_heroReaction = nullptr;
Expand All @@ -47,7 +48,6 @@ QObjectPetka::QObjectPetka() {
_surfH = 0;
_surfW = 0;
_k = 1.0;
_walk = nullptr;
}

void QObjectPetka::processMessage(const QMessage &arg) {
Expand All @@ -56,8 +56,7 @@ void QObjectPetka::processMessage(const QMessage &arg) {
msg.opcode = kSet;
_imageId = msg.arg1;

delete _walk;
_walk = new Walk(_imageId + 10);
_walk.reset(new Walk(_imageId + 10));

QObjectBG *room = g_vm->getQSystem()->_room;
if (room)
Expand Down
3 changes: 2 additions & 1 deletion engines/petka/objects/heroes.h
Expand Up @@ -23,6 +23,7 @@
#ifndef PETKA_HEROES_H
#define PETKA_HEROES_H

#include "common/ptr.h"
#include "petka/objects/object.h"

namespace Petka {
Expand Down Expand Up @@ -63,7 +64,7 @@ class QObjectPetka : public QObject {
// int _surfId;
int _imageId;
double _k;
Walk *_walk;
Common::ScopedPtr<Walk> _walk;
int _destX;
int _destY;
bool _isWalking;
Expand Down
1 change: 1 addition & 0 deletions engines/petka/objects/object.cpp
Expand Up @@ -374,6 +374,7 @@ static Common::String readString(Common::ReadStream &readStream) {
readStream.read(data, stringSize);
data[stringSize] = '\0';
Common::String str((char *)data);
free(data);
return str;
}

Expand Down
2 changes: 1 addition & 1 deletion engines/petka/petka.cpp
Expand Up @@ -197,7 +197,7 @@ void PetkaEngine::playVideo(Common::SeekableReadStream *stream) {
if (decoder.needsUpdate()) {
const Graphics::Surface *frame = decoder.decodeNextFrame();
if (frame) {
Common::ScopedPtr<Graphics::Surface> f(frame->convertTo(fmt));
Common::ScopedPtr<Graphics::Surface, Graphics::SurfaceDeleter> f(frame->convertTo(fmt));
_system->copyRectToScreen(f->getPixels(), f->pitch, 0, 0, f->w, f->h);
}
}
Expand Down
2 changes: 1 addition & 1 deletion engines/petka/sound.cpp
Expand Up @@ -84,7 +84,7 @@ Sound *SoundMgr::addSound(const Common::String &name, Audio::Mixer::SoundType ty
Common::SeekableReadStream *s = _vm.openFile(name, false);
if (s) {
debug("SoundMgr: added sound %s", name.c_str());
sound = new Sound(_vm.openFile(name, false), type);
sound = new Sound(s, type);
_sounds.getVal(name).reset(sound);
}
return sound;
Expand Down