Welcome to the Builder Academy

Question How to Free something after it's CREATE'd

More
05 Aug 2015 15:13 #5495 by ptrayal
Hello:
New to the tbaMUD forum's, but a long time follower. I started playing with a copy of Gicker's d20 mud base and converting it to a Pathfinder mud. Anyways, I've got a very obvious memory leak in it and I'm not familiar enough with Circle/TBA to know what I'm looking for. Anyway, something is CREATE'd, but I know of no way to free the memory it's using, so it's creating a leak. Is there a way to free memory once it's been CREATE'd?

Any help would be appreciated.

So, here's the code:
Code:
void postmaster_send_mail(struct char_data *ch, struct char_data *mailman, int cmd, char *arg) { long recipient; char buf[MAX_INPUT_LENGTH]={'\0'}, **mailwrite; one_argument(arg, buf); if (!*buf) { /* you'll get no argument from me! */ act("You need to specify an addressee!", FALSE, mailman, 0, ch, TO_VICT); return; } CREATE(mailwrite, char *, 1); if (!strcmp(buf, "all") && GET_ADMLEVEL(ch) == ADMLVL_IMPL) { act("$n starts to write some mail.", TRUE, ch, 0, 0, TO_ROOM); SET_BIT_AR(PLR_FLAGS(ch), PLR_MAILING); /* string_write() sets writing. */ /* Start writing! */ RECREATE(mailwrite, char *, 1); string_write(ch->desc, mailwrite, MAX_MAIL_SIZE, -999, NULL); } else if (!strcmp(buf, "staff") && GET_ADMLEVEL(ch) > 0) { act("$n starts to write some mail.", TRUE, ch, 0, 0, TO_ROOM); SET_BIT_AR(PLR_FLAGS(ch), PLR_MAILING); /* string_write() sets writing. */ /* Start writing! */ RECREATE(mailwrite, char *, 1); string_write(ch->desc, mailwrite, MAX_MAIL_SIZE, -899, NULL); } else { if ((recipient = get_id_by_name(buf)) < 0 || !mail_recip_ok(buf)) { act("No one by that name is registered here!", FALSE, mailman, 0, ch, TO_VICT); return; /* MEMORY LEAK HERE */ } act("$n starts to write some mail.", TRUE, ch, 0, 0, TO_ROOM); SET_BIT_AR(PLR_FLAGS(ch), PLR_MAILING); /* string_write() sets writing. */ /* Start writing! */ RECREATE(mailwrite, char *, 1); string_write(ch->desc, mailwrite, MAX_MAIL_SIZE, recipient, NULL); } }

Please Log in or Create an account to join the conversation.

More
05 Aug 2015 20:49 #5496 by thomas
free(mailwrite); doesn't work for you?

Please Log in or Create an account to join the conversation.

More
06 Aug 2015 00:25 #5497 by WhiskyTest
Yeah and if free() doesn't work, you could look at moving the code that checks for a valid recipient up so that it returns before the CREATE call.

You'd have to account for 'staff' and 'all' if you wanted to retain that functionality. I don't see how it loops through the player list without downloading the d20 code, but perhaps adding a check for valid recipient before the RECREATE calls which skips to the next person in the list.

This way nothing is CREATE'd or RECREATE'd unless we are going to use it.

Please Log in or Create an account to join the conversation.

Time to create page: 0.208 seconds