avoid mk_artifact()-related memory leaks
Reported directly to devteam after being discovered in nerfhack.
This commit is contained in:
21
src/mkobj.c
21
src/mkobj.c
@@ -9,7 +9,7 @@ staticfn boolean may_generate_eroded(struct obj *);
|
||||
staticfn void mkobj_erosions(struct obj *);
|
||||
staticfn void mkbox_cnts(struct obj *);
|
||||
staticfn unsigned nextoid(struct obj *, struct obj *);
|
||||
staticfn void mksobj_init(struct obj *, boolean);
|
||||
staticfn void mksobj_init(struct obj **, boolean);
|
||||
staticfn int item_on_ice(struct obj *);
|
||||
staticfn void shrinking_glob_gone(struct obj *);
|
||||
staticfn void obj_timer_checks(struct obj *, coordxy, coordxy, int);
|
||||
@@ -861,9 +861,10 @@ unknow_object(struct obj *obj)
|
||||
|
||||
/* do some initialization to newly created object; otyp must already be set */
|
||||
staticfn void
|
||||
mksobj_init(struct obj *otmp, boolean artif)
|
||||
mksobj_init(struct obj **obj, boolean artif)
|
||||
{
|
||||
int mndx, tryct;
|
||||
struct obj *otmp = *obj;
|
||||
char let = objects[otmp->otyp].oc_class;
|
||||
|
||||
switch (let) {
|
||||
@@ -880,8 +881,11 @@ mksobj_init(struct obj *otmp, boolean artif)
|
||||
if (is_poisonable(otmp) && !rn2(100))
|
||||
otmp->opoisoned = 1;
|
||||
|
||||
if (artif && !rn2(20 + (10 * nartifact_exist())))
|
||||
if (artif && !rn2(20 + (10 * nartifact_exist()))) {
|
||||
/* mk_artifact() with otmp and A_NONE will never return NULL */
|
||||
otmp = mk_artifact(otmp, (aligntyp) A_NONE, 99, TRUE);
|
||||
*obj = otmp;
|
||||
}
|
||||
break;
|
||||
case FOOD_CLASS:
|
||||
otmp->oeaten = 0;
|
||||
@@ -1085,8 +1089,11 @@ mksobj_init(struct obj *otmp, boolean artif)
|
||||
otmp->spe = rne(3);
|
||||
} else
|
||||
blessorcurse(otmp, 10);
|
||||
if (artif && !rn2(40 + (10 * nartifact_exist())))
|
||||
if (artif && !rn2(40 + (10 * nartifact_exist()))) {
|
||||
/* mk_artifact() with otmp and A_NONE will never return NULL */
|
||||
otmp = mk_artifact(otmp, (aligntyp) A_NONE, 99, TRUE);
|
||||
*obj = otmp;
|
||||
}
|
||||
/* simulate lacquered armor for samurai */
|
||||
if (Role_if(PM_SAMURAI) && otmp->otyp == SPLINT_MAIL
|
||||
&& (svm.moves <= 1 || In_quest(&u.uz))) {
|
||||
@@ -1176,7 +1183,7 @@ mksobj(int otyp, boolean init, boolean artif)
|
||||
otmp->pickup_prev = 0;
|
||||
|
||||
if (init)
|
||||
mksobj_init(otmp, artif);
|
||||
mksobj_init(&otmp, artif);
|
||||
|
||||
/* some things must get done (corpsenm, timers) even if init = 0 */
|
||||
switch ((otmp->oclass == POTION_CLASS && otmp->otyp != POT_OIL)
|
||||
@@ -1231,8 +1238,10 @@ mksobj(int otyp, boolean init, boolean artif)
|
||||
}
|
||||
|
||||
/* unique objects may have an associated artifact entry */
|
||||
if (objects[otyp].oc_unique && !otmp->oartifact)
|
||||
if (objects[otyp].oc_unique && !otmp->oartifact) {
|
||||
/* mk_artifact() with otmp and A_NONE will never return NULL */
|
||||
otmp = mk_artifact(otmp, (aligntyp) A_NONE, 99, FALSE);
|
||||
}
|
||||
otmp->owt = weight(otmp);
|
||||
return otmp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user