aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-10-12 16:10:04 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-10-12 16:10:04 +0300
commit36a0ea60d220a7edc0c83b73ad1867fd347ca77e (patch)
treece6a227382a2d3ec6ca0da05f66cfdf3eb01b2ff /src
parentb6678bb65fce1f64e82cc049aae3d7ba6f8aa19c (diff)
downloadvmod-binlog-36a0ea60d220a7edc0c83b73ad1867fd347ca77e.tar.gz
vmod-binlog-36a0ea60d220a7edc0c83b73ad1867fd347ca77e.tar.bz2
Handle eventual out-of-memory conditions.
Diffstat (limited to 'src')
-rw-r--r--src/binlog.c2
-rw-r--r--src/pack.c21
2 files changed, 21 insertions, 2 deletions
diff --git a/src/binlog.c b/src/binlog.c
index 6f438a8..b2d9f87 100644
--- a/src/binlog.c
+++ b/src/binlog.c
@@ -209,12 +209,14 @@ vmod_init(struct sess *sp, struct vmod_priv *priv,
209 AN(conf->dir); 209 AN(conf->dir);
210 210
211 conf->inst_head = packcomp(dataspec, &p); 211 conf->inst_head = packcomp(dataspec, &p);
212 AN(conf->inst_head);
212 if (*p) { 213 if (*p) {
213 binlog_error("cannot compile data format near %s", p); 214 binlog_error("cannot compile data format near %s", p);
214 abort(); 215 abort();
215 } 216 }
216 conf->recsize = packsize(conf->inst_head); 217 conf->recsize = packsize(conf->inst_head);
217 conf->env = packenv_create(conf->recsize); 218 conf->env = packenv_create(conf->recsize);
219 AN(conf->env);
218 conf->recsize += offsetof(struct binlog_record,data); 220 conf->recsize += offsetof(struct binlog_record,data);
219 conf->dataspec = strdup(dataspec); 221 conf->dataspec = strdup(dataspec);
220 AN(conf->dataspec); 222 AN(conf->dataspec);
diff --git a/src/pack.c b/src/pack.c
index a6ee933..5594bb1 100644
--- a/src/pack.c
+++ b/src/pack.c
@@ -432,6 +432,8 @@ packcomp(const char *s, char **endp)
432 if (getrep(s + 1, &s, &rep)) 432 if (getrep(s + 1, &s, &rep))
433 break; 433 break;
434 pi = malloc(sizeof(*pi)); 434 pi = malloc(sizeof(*pi));
435 if (!pi)
436 return NULL;
435 pi->next = NULL; 437 pi->next = NULL;
436 pi->spec = ps; 438 pi->spec = ps;
437 pi->rep = rep; 439 pi->rep = rep;
@@ -515,8 +517,14 @@ struct packenv *
515packenv_create(size_t size) 517packenv_create(size_t size)
516{ 518{
517 struct packenv *env = calloc(1, sizeof(*env)); 519 struct packenv *env = calloc(1, sizeof(*env));
518 env->buf_base = calloc(1, size); 520 if (env) {
519 env->buf_size = size; 521 env->buf_base = calloc(1, size);
522 if (!env->buf_base) {
523 free(env);
524 return NULL;
525 }
526 env->buf_size = size;
527 }
520 return env; 528 return env;
521} 529}
522 530
@@ -565,11 +573,20 @@ main(int argc, char **argv)
565 abort(); 573 abort();
566 574
567 pi = packcomp(argv[0], &end); 575 pi = packcomp(argv[0], &end);
576 if (!pi) {
577 fprintf(stderr, "out of memory\n");
578 abort();
579 }
568 if (*end) { 580 if (*end) {
569 fprintf(stderr, "compile error near %s\n", end); 581 fprintf(stderr, "compile error near %s\n", end);
570 exit(1); 582 exit(1);
571 } 583 }
572 env = packenv_create(packsize(pi)); 584 env = packenv_create(packsize(pi));
585 if (!env) {
586 fprintf(stderr, "out of memory\n");
587 abort();
588 }
589
573 env->fp = stdout; 590 env->fp = stdout;
574 env->argv = argv + 1; 591 env->argv = argv + 1;
575 env->argc = argc - 1; 592 env->argc = argc - 1;

Return to:

Send suggestions and report system problems to the System administrator.