region memory

<Someone> wrote on Tuesday, July 27, 2004 at 06:46:15
> In the region.c function rest_regions allocates storage for the possible
> enter_msg and leave_msg strings. But the function free_region does not relese
> this storage.

Also ensures that some code that is currently ifdef'd out
makes copies of the strings into memory from alloc()
to ensure that no problems with free() result if the function
gets passed a literal string.
This commit is contained in:
nethack.allison
2006-07-03 14:30:01 +00:00
parent 230d150350
commit 4b1c4728d6

View File

@@ -274,6 +274,10 @@ NhRegion *reg;
free((genericptr_t) reg->rects);
if (reg->monsters)
free((genericptr_t) reg->monsters);
if (reg->enter_msg)
free((genericptr_t) reg->enter_msg);
if (reg->leave_msg)
free((genericptr_t) reg->leave_msg);
free((genericptr_t) reg);
}
}
@@ -791,8 +795,14 @@ const char *msg_leave;
NhRect tmprect;
NhRegion *reg = create_region((NhRect *) 0, 0);
reg->enter_msg = msg_enter;
reg->leave_msg = msg_leave;
if (msg_enter) {
reg->enter_msg = (const char *) alloc(strlen(msg_enter) + 1);
Strcpy(reg->enter_msg, msg_enter);
}
if (msg_leave) {
reg->leave_msg = (const char *) alloc(strlen(msg_leave) + 1);
Strcpy(reg->leave_msg, msg_leave);
}
tmprect.lx = x;
tmprect.ly = y;
tmprect.hx = x + w;