(mission): Plug memory leak. s_char purge.
This commit is contained in:
parent
7d5a6b817e
commit
9646854705
1 changed files with 15 additions and 13 deletions
|
@ -50,6 +50,12 @@
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
|
||||||
|
union item_u {
|
||||||
|
struct shpstr ship;
|
||||||
|
struct plnstr plane;
|
||||||
|
struct lndstr land;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
|
* mission <type> <planes/ships/units> <mission type> <op sector> [<radius>]
|
||||||
*/
|
*/
|
||||||
|
@ -57,19 +63,18 @@ int
|
||||||
mission(void)
|
mission(void)
|
||||||
{
|
{
|
||||||
static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
|
static int ef_with_missions[] = { EF_SHIP, EF_LAND, EF_PLANE, EF_BAD };
|
||||||
s_char *p;
|
char *p;
|
||||||
int type;
|
int type;
|
||||||
int mission;
|
int mission;
|
||||||
coord x, y;
|
coord x, y;
|
||||||
size_t size;
|
|
||||||
int desired_radius, radius;
|
int desired_radius, radius;
|
||||||
struct sctstr opsect;
|
struct sctstr opsect;
|
||||||
s_char *block;
|
union item_u item;
|
||||||
struct genitem *gp;
|
struct genitem *gp;
|
||||||
int num = 0, mobmax, mobused, dist;
|
int num = 0, mobmax, mobused, dist;
|
||||||
struct nstr_item ni;
|
struct nstr_item ni;
|
||||||
s_char prompt[128];
|
char prompt[128];
|
||||||
s_char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
if ((p =
|
if ((p =
|
||||||
getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
|
getstarg(player->argp[1], "Ship, plane or land unit (p,sh,la)? ",
|
||||||
|
@ -189,9 +194,6 @@ mission(void)
|
||||||
desired_radius = 9999;
|
desired_radius = 9999;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = MAX(sizeof(struct lndstr), sizeof(struct plnstr));
|
|
||||||
size = MAX(size, sizeof(struct shpstr));
|
|
||||||
block = malloc(size);
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EF_SHIP:
|
case EF_SHIP:
|
||||||
mobmax = ship_mob_max;
|
mobmax = ship_mob_max;
|
||||||
|
@ -206,8 +208,8 @@ mission(void)
|
||||||
|
|
||||||
mobused = ldround((mission_mob_cost * (double)mobmax), 1);
|
mobused = ldround((mission_mob_cost * (double)mobmax), 1);
|
||||||
|
|
||||||
while (nxtitem(&ni, block)) {
|
while (nxtitem(&ni, &item)) {
|
||||||
gp = (struct genitem *)block;
|
gp = (struct genitem *)&item;
|
||||||
|
|
||||||
if (!player->owner || gp->own == 0)
|
if (!player->owner || gp->own == 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -348,13 +350,13 @@ mission(void)
|
||||||
gp->opy = y;
|
gp->opy = y;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case EF_SHIP:
|
case EF_SHIP:
|
||||||
putship(gp->uid, block);
|
putship(gp->uid, &item.ship);
|
||||||
break;
|
break;
|
||||||
case EF_LAND:
|
case EF_LAND:
|
||||||
putland(gp->uid, block);
|
putland(gp->uid, &item.land);
|
||||||
break;
|
break;
|
||||||
case EF_PLANE:
|
case EF_PLANE:
|
||||||
putplane(gp->uid, block);
|
putplane(gp->uid, &item.plane);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue