Changeset 650

Show
Ignore:
Timestamp:
11/21/07 19:58:47 (1 year ago)
Author:
dormando
Message:

Fix bugs reported by Tomash Brechko for the new cas patch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/memcached.c

    r646 r650  
    408408    if (c->suffixleft != 0) { 
    409409        for (; c->suffixleft > 0; c->suffixleft--, c->suffixcurr++) { 
    410             suffix_add_to_freelist(*(c->suffixcurr)); 
     410            if(suffix_add_to_freelist(*(c->suffixcurr))) { 
     411                free(*(c->suffixcurr)); 
     412            } 
    411413        } 
    412414    } 
     
    554556    freesuffixcurr  = 0; 
    555557 
    556     freesuffix = (char **)malloc( sizeof(char *) * 
    557                                   21 * freesuffixtotal ); 
     558    freesuffix = (char **)malloc( sizeof(char *) * freesuffixtotal ); 
    558559    if (freesuffix == NULL) { 
    559560        perror("malloc()"); 
     
    572573        s = freesuffix[--freesuffixcurr]; 
    573574    } else { 
    574         /* FIXME: global define? */ 
    575575        /* If malloc fails, let the logic fall through without spamming 
    576576         * STDERR on the server. */ 
     
    591591    } else { 
    592592        /* try to enlarge free connections array */ 
    593         char **new_freesuffix = realloc(freesuffix, 
    594                                         SUFFIX_SIZE * freesuffixtotal * 2); 
     593        char **new_freesuffix = realloc(freesuffix, freesuffixtotal * 2); 
    595594        if (new_freesuffix) { 
    596595            freesuffixtotal *= 2; 
     
    12421241                      c->suffixsize *= 2; 
    12431242                      c->suffixlist  = new_suffix_list; 
    1244                     } 
     1243                    } else break; 
    12451244                  } 
    12461245 
     
    22202219                        while (c->suffixleft > 0) { 
    22212220                            char *suffix = *(c->suffixcurr); 
    2222                             suffix_add_to_freelist(suffix); 
     2221                            if(suffix_add_to_freelist(suffix)) { 
     2222                                /* Failed to add to freelist, don't leak */ 
     2223                                free(suffix); 
     2224                            } 
    22232225                            c->suffixcurr++; 
    22242226                            c->suffixleft--; 
  • trunk/server/memcached.h

    r646 r650  
    1818#define MAX_SENDBUF_SIZE (256 * 1024 * 1024) 
    1919/* I'm told the max legnth of a 64-bit num converted to string is 20 bytes. 
    20  * Plus one for good luck. */ 
    21 #define SUFFIX_SIZE 21 
     20 * Plus a few for spaces, \r\n, \0 */ 
     21#define SUFFIX_SIZE 24 
    2222 
    2323/** Initial size of list of items being returned by "get". */