Show
Ignore:
Timestamp:
05/20/06 17:24:37 (8 years ago)
Author:
mmh
Message:

Previous leak fix caused multiple sensors_init() calls to break.
This patch fixes that by managing the scanner buffers manually.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/conf-lex.l

    r3296 r3300  
    2626#include "conf-parse.h" 
    2727#include "error.h" 
     28#include "scanner.h" 
    2829 
    2930static int buffer_count; 
     
    4950 
    5051%option nodefault 
     52%option noyywrap 
    5153%option yylineno 
    5254%option nounput 
     
    270272%% 
    271273 
    272 int sensors_yywrap(void) 
     274/* 
     275        Do the buffer handling manually.  This allows us to scan as many 
     276        config files as we need to, while cleaning up properly after each 
     277        one.  The "BEGIN(0)" line ensures that we start in the default state, 
     278        even if e.g. the previous config file was syntactically broken. 
     279 
     280        Returns 0 if successful, !0 otherwise. 
     281*/ 
     282 
     283static YY_BUFFER_STATE scan_buf = (YY_BUFFER_STATE)0; 
     284 
     285int sensors_scanner_init(FILE *input) 
    273286{ 
    274   yy_delete_buffer(YY_CURRENT_BUFFER); 
    275   return 1; 
     287        BEGIN(0); 
     288        if (!(scan_buf = sensors_yy_create_buffer(input, YY_BUF_SIZE))) 
     289                return -1; 
     290 
     291        sensors_yy_switch_to_buffer(scan_buf); 
     292        return 0; 
    276293} 
    277294 
     295void sensors_scanner_exit(void) 
     296{ 
     297        sensors_yy_delete_buffer(scan_buf); 
     298        scan_buf = (YY_BUFFER_STATE)0; 
     299} 
     300