aboutsummaryrefslogtreecommitdiff
path: root/src/variable.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/variable.c')
-rw-r--r--src/variable.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/variable.c b/src/variable.c
index e6bad1a..6b23c00 100644
--- a/src/variable.c
+++ b/src/variable.c
@@ -1,27 +1,27 @@
1/* This file is part of vmod-tbf 1/* This file is part of vmod-variable
2 Copyright (C) 2013-2015 Sergey Poznyakoff 2 Copyright (C) 2013-2016 Sergey Poznyakoff
3 3
4 Vmod-tbf is free software; you can redistribute it and/or modify 4 Vmod-variable is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option) 6 the Free Software Foundation; either version 3, or (at your option)
7 any later version. 7 any later version.
8 8
9 Vmod-tbf is distributed in the hope that it will be useful, 9 Vmod-variable is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details. 12 GNU General Public License for more details.
13 13
14 You should have received a copy of the GNU General Public License 14 You should have received a copy of the GNU General Public License
15 along with vmod-tbf. If not, see <http://www.gnu.org/licenses/>. 15 along with vmod-variable. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17#include <config.h> 17#include <config.h>
18#include <stdlib.h> 18#include <stdlib.h>
19#include <stdarg.h> 19#include <stdarg.h>
20#include <syslog.h> 20#include <syslog.h>
21#include <ctype.h> 21#include <ctype.h>
22#include <pcre.h> 22#include <pcre.h>
23#include "vrt.h" 23#include "vrt.h"
24#include "vcc_if.h" 24#include "vcc_if.h"
25#include "pthread.h" 25#include "pthread.h"
26#if VARNISHVERSION == 3 26#if VARNISHVERSION == 3
27# include "bin/varnishd/cache.h" 27# include "bin/varnishd/cache.h"
@@ -173,24 +173,27 @@ symtab_remove(struct symtab *st, const char *name)
173 struct variable *entry; 173 struct variable *entry;
174 174
175 pos = hash_string(name, hash_size[st->hash_num]); 175 pos = hash_string(name, hash_size[st->hash_num]);
176 for (i = pos; (entry = st->tab[i]);) { 176 for (i = pos; (entry = st->tab[i]);) {
177 if (strcmp(entry->name, name) == 0) 177 if (strcmp(entry->name, name) == 0)
178 break; 178 break;
179 if (++i >= hash_size[st->hash_num]) 179 if (++i >= hash_size[st->hash_num])
180 i = 0; 180 i = 0;
181 if (i == pos) 181 if (i == pos)
182 return ENOENT; 182 return ENOENT;
183 } 183 }
184 184
185 if (!entry)
186 return ENOENT;
187
185 var_free(entry); 188 var_free(entry);
186 189
187 for (;;) { 190 for (;;) {
188 st->tab[i] = NULL; 191 st->tab[i] = NULL;
189 j = i; 192 j = i;
190 193
191 do { 194 do {
192 if (++i >= hash_size[st->hash_num]) 195 if (++i >= hash_size[st->hash_num])
193 i = 0; 196 i = 0;
194 if (!st->tab[i]) 197 if (!st->tab[i])
195 return 0; 198 return 0;
196 r = hash_string(st->tab[i]->name, hash_size[st->hash_num]); 199 r = hash_string(st->tab[i]->name, hash_size[st->hash_num]);
@@ -383,24 +386,25 @@ vmod_global_unset(VARIABLE_CTX ctx, VCL_STRING name)
383 386
384static struct symtab * 387static struct symtab *
385get_symtab(VARIABLE_CTX ctx) 388get_symtab(VARIABLE_CTX ctx)
386{ 389{
387 struct symtab *st; 390 struct symtab *st;
388 int fd = ctx->req->sp->fd; 391 int fd = ctx->req->sp->fd;
389 392
390 assert(fd >= 0); 393 assert(fd >= 0);
391 AZ(pthread_mutex_lock(&symtab_mtx)); 394 AZ(pthread_mutex_lock(&symtab_mtx));
392 if (symtabc <= fd) { 395 if (symtabc <= fd) {
393 size_t n = fd + 1; 396 size_t n = fd + 1;
394 symtabv = realloc(symtabv, n * sizeof(symtabv[0])); 397 symtabv = realloc(symtabv, n * sizeof(symtabv[0]));
398 AN(symtabv);
395 while (symtabc < n) 399 while (symtabc < n)
396 symtabv[symtabc++] = NULL; 400 symtabv[symtabc++] = NULL;
397 } 401 }
398 if (!symtabv[fd]) 402 if (!symtabv[fd])
399 symtabv[fd] = symtab_create(); 403 symtabv[fd] = symtab_create();
400 st = symtabv[fd]; 404 st = symtabv[fd];
401 if (st->vxid != ctx->req->sp->vxid) 405 if (st->vxid != ctx->req->sp->vxid)
402 symtab_clear(st); 406 symtab_clear(st);
403 st->vxid = ctx->req->sp->vxid; 407 st->vxid = ctx->req->sp->vxid;
404 AZ(pthread_mutex_unlock(&symtab_mtx)); 408 AZ(pthread_mutex_unlock(&symtab_mtx));
405 return st; 409 return st;
406} 410}

Return to:

Send suggestions and report system problems to the System administrator.