From: Rudolf Polzer Date: Fri, 27 Nov 2015 20:56:11 +0000 (+0100) Subject: Fix memory leaks in ATTRIB(..., strzone(...)) calls. X-Git-Tag: xonotic-v0.8.2~1612 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=09dd62bfe9825f234670de0409a129c636833c5e;p=xonotic%2Fxonotic-data.pk3dir.git Fix memory leaks in ATTRIB(..., strzone(...)) calls. These calls don't free the previously allocated string in the same field, causing a leak. --- diff --git a/qcsrc/common/turrets/turret/ewheel.qc b/qcsrc/common/turrets/turret/ewheel.qc index 3875f1bdf..1d4647341 100644 --- a/qcsrc/common/turrets/turret/ewheel.qc +++ b/qcsrc/common/turrets/turret/ewheel.qc @@ -10,8 +10,8 @@ CLASS(EWheel, Turret) /* mins */ ATTRIB(EWheel, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(EWheel, maxs, vector, '32 32 48'); /* modelname */ ATTRIB(EWheel, mdl, string, "ewheel-base2.md3"); -/* model */ ATTRIB(EWheel, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(EWheel, head_model, string, strzone(strcat("models/turrets/", "ewheel-gun1.md3"))); +/* model */ ATTRIB_STRZONE(EWheel, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(EWheel, head_model, string, strcat("models/turrets/", "ewheel-gun1.md3")); /* netname */ ATTRIB(EWheel, netname, string, "ewheel"); /* fullname */ ATTRIB(EWheel, turret_name, string, _("eWheel Turret")); ATTRIB(EWheel, m_weapon, Weapon, WEP_EWHEEL); diff --git a/qcsrc/common/turrets/turret/flac.qc b/qcsrc/common/turrets/turret/flac.qc index 1c9122f67..faaf89ffc 100644 --- a/qcsrc/common/turrets/turret/flac.qc +++ b/qcsrc/common/turrets/turret/flac.qc @@ -8,8 +8,8 @@ CLASS(Flac, Turret) /* mins */ ATTRIB(Flac, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(Flac, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(Flac, mdl, string, "base.md3"); -/* model */ ATTRIB(Flac, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(Flac, head_model, string, strzone(strcat("models/turrets/", "flac.md3"))); +/* model */ ATTRIB_STRZONE(Flac, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(Flac, head_model, string, strcat("models/turrets/", "flac.md3")); /* netname */ ATTRIB(Flac, netname, string, "flac"); /* fullname */ ATTRIB(Flac, turret_name, string, _("FLAC Cannon")); ATTRIB(Flac, m_weapon, Weapon, WEP_FLAC); diff --git a/qcsrc/common/turrets/turret/fusionreactor.qc b/qcsrc/common/turrets/turret/fusionreactor.qc index 3f51c06c3..889ba79a0 100644 --- a/qcsrc/common/turrets/turret/fusionreactor.qc +++ b/qcsrc/common/turrets/turret/fusionreactor.qc @@ -6,8 +6,8 @@ CLASS(FusionReactor, Turret) /* mins */ ATTRIB(FusionReactor, mins, vector, '-34 -34 0'); /* maxs */ ATTRIB(FusionReactor, maxs, vector, '34 34 90'); /* modelname */ ATTRIB(FusionReactor, mdl, string, "base.md3"); -/* model */ ATTRIB(FusionReactor, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(FusionReactor, head_model, string, strzone(strcat("models/turrets/", "reactor.md3"))); +/* model */ ATTRIB_STRZONE(FusionReactor, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(FusionReactor, head_model, string, strcat("models/turrets/", "reactor.md3")); /* netname */ ATTRIB(FusionReactor, netname, string, "fusionreactor"); /* fullname */ ATTRIB(FusionReactor, turret_name, string, _("Fusion Reactor")); ENDCLASS(FusionReactor) diff --git a/qcsrc/common/turrets/turret/hellion.qc b/qcsrc/common/turrets/turret/hellion.qc index 203be93db..dc256e987 100644 --- a/qcsrc/common/turrets/turret/hellion.qc +++ b/qcsrc/common/turrets/turret/hellion.qc @@ -8,8 +8,8 @@ CLASS(Hellion, Turret) /* mins */ ATTRIB(Hellion, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(Hellion, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(Hellion, mdl, string, "base.md3"); -/* model */ ATTRIB(Hellion, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(Hellion, head_model, string, strzone(strcat("models/turrets/", "hellion.md3"))); +/* model */ ATTRIB_STRZONE(Hellion, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(Hellion, head_model, string, strcat("models/turrets/", "hellion.md3")); /* netname */ ATTRIB(Hellion, netname, string, "hellion"); /* fullname */ ATTRIB(Hellion, turret_name, string, _("Hellion Missile Turret")); ATTRIB(Hellion, m_weapon, Weapon, WEP_HELLION); diff --git a/qcsrc/common/turrets/turret/hk.qc b/qcsrc/common/turrets/turret/hk.qc index 61d8318db..c5ddc6fc8 100644 --- a/qcsrc/common/turrets/turret/hk.qc +++ b/qcsrc/common/turrets/turret/hk.qc @@ -10,8 +10,8 @@ CLASS(HunterKiller, Turret) /* mins */ ATTRIB(HunterKiller, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(HunterKiller, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(HunterKiller, mdl, string, "base.md3"); -/* model */ ATTRIB(HunterKiller, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(HunterKiller, head_model, string, strzone(strcat("models/turrets/", "hk.md3"))); +/* model */ ATTRIB_STRZONE(HunterKiller, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(HunterKiller, head_model, string, strcat("models/turrets/", "hk.md3")); /* netname */ ATTRIB(HunterKiller, netname, string, "hk"); /* fullname */ ATTRIB(HunterKiller, turret_name, string, _("Hunter-Killer Turret")); ATTRIB(HunterKiller, m_weapon, Weapon, WEP_HK); diff --git a/qcsrc/common/turrets/turret/machinegun.qc b/qcsrc/common/turrets/turret/machinegun.qc index 9911b97c6..61f256d7a 100644 --- a/qcsrc/common/turrets/turret/machinegun.qc +++ b/qcsrc/common/turrets/turret/machinegun.qc @@ -8,8 +8,8 @@ CLASS(MachineGunTurret, Turret) /* mins */ ATTRIB(MachineGunTurret, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(MachineGunTurret, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(MachineGunTurret, mdl, string, "base.md3"); -/* model */ ATTRIB(MachineGunTurret, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(MachineGunTurret, head_model, string, strzone(strcat("models/turrets/", "machinegun.md3"))); +/* model */ ATTRIB_STRZONE(MachineGunTurret, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(MachineGunTurret, head_model, string, strcat("models/turrets/", "machinegun.md3")); /* netname */ ATTRIB(MachineGunTurret, netname, string, "machinegun"); /* fullname */ ATTRIB(MachineGunTurret, turret_name, string, _("Machinegun Turret")); ATTRIB(MachineGunTurret, m_weapon, Weapon, WEP_TUR_MACHINEGUN); diff --git a/qcsrc/common/turrets/turret/mlrs.qc b/qcsrc/common/turrets/turret/mlrs.qc index ae2d1d47c..3583af9f0 100644 --- a/qcsrc/common/turrets/turret/mlrs.qc +++ b/qcsrc/common/turrets/turret/mlrs.qc @@ -8,8 +8,8 @@ CLASS(MLRSTurret, Turret) /* mins */ ATTRIB(MLRSTurret, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(MLRSTurret, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(MLRSTurret, mdl, string, "base.md3"); -/* model */ ATTRIB(MLRSTurret, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(MLRSTurret, head_model, string, strzone(strcat("models/turrets/", "mlrs.md3"))); +/* model */ ATTRIB_STRZONE(MLRSTurret, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(MLRSTurret, head_model, string, strcat("models/turrets/", "mlrs.md3")); /* netname */ ATTRIB(MLRSTurret, netname, string, "mlrs"); /* fullname */ ATTRIB(MLRSTurret, turret_name, string, _("MLRS Turret")); ATTRIB(MLRSTurret, m_weapon, Weapon, WEP_TUR_MLRS); diff --git a/qcsrc/common/turrets/turret/phaser.qc b/qcsrc/common/turrets/turret/phaser.qc index 24d4d30c5..24a476c03 100644 --- a/qcsrc/common/turrets/turret/phaser.qc +++ b/qcsrc/common/turrets/turret/phaser.qc @@ -8,8 +8,8 @@ CLASS(PhaserTurret, Turret) /* mins */ ATTRIB(PhaserTurret, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(PhaserTurret, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(PhaserTurret, mdl, string, "base.md3"); -/* model */ ATTRIB(PhaserTurret, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(PhaserTurret, head_model, string, strzone(strcat("models/turrets/", "phaser.md3"))); +/* model */ ATTRIB_STRZONE(PhaserTurret, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(PhaserTurret, head_model, string, strcat("models/turrets/", "phaser.md3")); /* netname */ ATTRIB(PhaserTurret, netname, string, "phaser"); /* fullname */ ATTRIB(PhaserTurret, turret_name, string, _("Phaser Cannon")); ATTRIB(PhaserTurret, m_weapon, Weapon, WEP_PHASER); diff --git a/qcsrc/common/turrets/turret/plasma.qc b/qcsrc/common/turrets/turret/plasma.qc index 7ed255911..c36423381 100644 --- a/qcsrc/common/turrets/turret/plasma.qc +++ b/qcsrc/common/turrets/turret/plasma.qc @@ -8,8 +8,8 @@ CLASS(PlasmaTurret, Turret) /* mins */ ATTRIB(PlasmaTurret, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(PlasmaTurret, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(PlasmaTurret, mdl, string, "base.md3"); -/* model */ ATTRIB(PlasmaTurret, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(PlasmaTurret, head_model, string, strzone(strcat("models/turrets/", "plasma.md3"))); +/* model */ ATTRIB_STRZONE(PlasmaTurret, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(PlasmaTurret, head_model, string, strcat("models/turrets/", "plasma.md3")); /* netname */ ATTRIB(PlasmaTurret, netname, string, "plasma"); /* fullname */ ATTRIB(PlasmaTurret, turret_name, string, _("Plasma Cannon")); ATTRIB(PlasmaTurret, m_weapon, Weapon, WEP_PLASMA); diff --git a/qcsrc/common/turrets/turret/plasma_dual.qc b/qcsrc/common/turrets/turret/plasma_dual.qc index cb78547a2..d39181582 100644 --- a/qcsrc/common/turrets/turret/plasma_dual.qc +++ b/qcsrc/common/turrets/turret/plasma_dual.qc @@ -12,8 +12,8 @@ CLASS(DualPlasmaTurret, PlasmaTurret) /* mins */ ATTRIB(DualPlasmaTurret, mins, vector, '-32 -32 0'); /* maxs */ ATTRIB(DualPlasmaTurret, maxs, vector, '32 32 64'); /* modelname */ ATTRIB(DualPlasmaTurret, mdl, string, "base.md3"); -/* model */ ATTRIB(DualPlasmaTurret, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(DualPlasmaTurret, head_model, string, strzone(strcat("models/turrets/", "plasmad.md3"))); +/* model */ ATTRIB_STRZONE(DualPlasmaTurret, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(DualPlasmaTurret, head_model, string, strcat("models/turrets/", "plasmad.md3")); /* netname */ ATTRIB(DualPlasmaTurret, netname, string, "plasma_dual"); /* fullname */ ATTRIB(DualPlasmaTurret, turret_name, string, _("Dual Plasma Cannon")); ATTRIB(DualPlasmaTurret, m_weapon, Weapon, WEP_PLASMA_DUAL); diff --git a/qcsrc/common/turrets/turret/tesla.qc b/qcsrc/common/turrets/turret/tesla.qc index 16a9e423d..051137c4f 100644 --- a/qcsrc/common/turrets/turret/tesla.qc +++ b/qcsrc/common/turrets/turret/tesla.qc @@ -8,8 +8,8 @@ CLASS(TeslaCoil, Turret) /* mins */ ATTRIB(TeslaCoil, mins, vector, '-60 -60 0'); /* maxs */ ATTRIB(TeslaCoil, maxs, vector, '60 60 128'); /* modelname */ ATTRIB(TeslaCoil, mdl, string, "tesla_base.md3"); -/* model */ ATTRIB(TeslaCoil, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(TeslaCoil, head_model, string, strzone(strcat("models/turrets/", "tesla_head.md3"))); +/* model */ ATTRIB_STRZONE(TeslaCoil, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(TeslaCoil, head_model, string, strcat("models/turrets/", "tesla_head.md3")); /* netname */ ATTRIB(TeslaCoil, netname, string, "tesla"); /* fullname */ ATTRIB(TeslaCoil, turret_name, string, _("Tesla Coil")); ATTRIB(TeslaCoil, m_weapon, Weapon, WEP_TESLA); diff --git a/qcsrc/common/turrets/turret/walker.qc b/qcsrc/common/turrets/turret/walker.qc index f7c5e48f6..97167eb36 100644 --- a/qcsrc/common/turrets/turret/walker.qc +++ b/qcsrc/common/turrets/turret/walker.qc @@ -10,8 +10,8 @@ CLASS(WalkerTurret, Turret) /* mins */ ATTRIB(WalkerTurret, mins, vector, '-70 -70 0'); /* maxs */ ATTRIB(WalkerTurret, maxs, vector, '70 70 95'); /* modelname */ ATTRIB(WalkerTurret, mdl, string, "walker_body.md3"); -/* model */ ATTRIB(WalkerTurret, model, string, strzone(strcat("models/turrets/", this.mdl))); -/* head_model */ ATTRIB(WalkerTurret, head_model, string, strzone(strcat("models/turrets/", "walker_head_minigun.md3"))); +/* model */ ATTRIB_STRZONE(WalkerTurret, model, string, strcat("models/turrets/", this.mdl)); +/* head_model */ ATTRIB_STRZONE(WalkerTurret, head_model, string, strcat("models/turrets/", "walker_head_minigun.md3")); /* netname */ ATTRIB(WalkerTurret, netname, string, "walker"); /* fullname */ ATTRIB(WalkerTurret, turret_name, string, _("Walker Turret")); ATTRIB(WalkerTurret, m_weapon, Weapon, WEP_WALKER); diff --git a/qcsrc/lib/oo.qh b/qcsrc/lib/oo.qh index a0d6f35db..e7d9a13b1 100644 --- a/qcsrc/lib/oo.qh +++ b/qcsrc/lib/oo.qh @@ -162,9 +162,19 @@ STATIC_INIT(RegisterClasses) class(cname).type name; \ INIT(cname) \ { \ + noref bool strzone; /* Error on strzone() calls. */ \ this.name = val; \ } +#define ATTRIB_STRZONE(cname, name, type, val) \ + class(cname).type name; \ + INIT(cname) \ + { \ + if (this.name) \ + strunzone(this.name); \ + this.name = strzone(val); \ + } + #define ATTRIBARRAY(cname, name, type, cnt) \ class(cname).type name[cnt];