PennMUSH Community

Changeset 1275

Show
Ignore:
Timestamp:
09/18/08 21:05:33 (2 months ago)
Author:
shawnw
Message:

Significantly drop memory usage in @sitelock rules.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/devel/CHANGES.183

    r1263 r1275  
    3737   similiar problems triggered by tests, by passing the --valgrind option 
    3838   to test scripts. 
    39  * baseconv() now supports up to base64. 
     39 * Significantly reduce memory usage in @sitelock rules.  
    4040 
    4141Commands: 
     
    6363 * ljust() and rjust() take fill strings now, not just single 
    6464   characters. Suggested by Nyssa, patch by Talvo. 
     65 * baseconv() now supports up to base64. 
    6566 
    6667Fixes: 
  • 1.8.3/branches/devel/hdrs/access.h

    r1066 r1275  
    77 */ 
    88struct access { 
    9   char host[BUFFER_LEN];        /**< The host pattern */ 
    10   char comment[BUFFER_LEN];     /**< A comment about the rule */ 
     9  char *host;        /**< The host pattern */ 
     10  char *comment;     /**< A comment about the rule */ 
    1111  dbref who;                    /**< Who created this rule if sitelock used */ 
    1212  uint32_t can;                      /**< Bitflags of what the host can do */ 
  • 1.8.3/branches/devel/src/access.c

    r1213 r1275  
    119119extern const unsigned char *tables; 
    120120 
     121static void 
     122sitelock_free(struct access *ap) 
     123{ 
     124  mush_free(ap->host, "sitelock.rule.host"); 
     125  if (ap->comment) 
     126    mush_free(ap->comment, "sitelock.rule.comment"); 
     127  if (ap->re) 
     128    free(ap); 
     129  mush_free(ap, "sitelock.rule"); 
     130} 
     131 
    121132static struct access * 
    122133sitelock_alloc(const char *host, dbref who, 
     
    141152  tmp->can = can; 
    142153  tmp->cant = cant; 
    143   mush_strncpy(tmp->host, host, BUFFER_LEN); 
    144   if (comment
    145     mush_strncpy(tmp->comment, comment, BUFFER_LEN); 
     154  tmp->host = mush_strdup(host, "sitelock.rule.host"); 
     155  if (comment && *comment
     156    tmp->comment = mush_strdup(comment, "sitelock.rule.comment"); 
    146157  else 
    147     tmp->comment[0] = '\0'
     158    tmp->comment = NULL
    148159  tmp->next = NULL; 
    149160 
     
    152163    tmp->re = pcre_compile(host, 0, errptr, &erroffset, tables); 
    153164    if (!tmp->re) { 
    154       mush_free(tmp, "sitelock.rule"); 
     165      sitelock_free(tmp); 
    155166      return NULL; 
    156167    } 
     
    307318        break; 
    308319      } 
    309       if (ap->comment && *ap->comment
     320      if (ap->comment
    310321        fprintf(fp, "# %s\n", ap->comment); 
    311322      else 
    312         fprintf(fp, "\n"); 
     323        fputc('\n', fp); 
    313324    } 
    314325    fclose(fp); 
     
    607618        : deletethis == rulenum) { 
    608619      n++; 
    609       if (ap->re) 
    610         free(ap->re); 
    611       mush_free(ap, "sitelock.rule"); 
     620      sitelock_free(ap); 
    612621      if (prev) 
    613622        prev->next = next; 
     
    633642  while (ap) { 
    634643    next = ap->next; 
    635     if (ap->re) 
    636       free(ap->re); 
    637     mush_free(ap, "sitelock.rule"); 
     644    sitelock_free(ap); 
    638645    ap = next; 
    639646  } 
     
    676683                    "%3d SITE: %-20s  DBREF: %-6s FLAGS:%s", rulenum, 
    677684                    ap->host, unparse_dbref(ap->who), flaglist); 
    678       notify_format(player, " COMMENT: %s", ap->comment); 
     685      notify_format(player, " COMMENT: %s", ap->comment ? comment : ""); 
    679686    } else { 
    680687      notify(player,