Skip to content

Commit

Permalink
zero out after realloc
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Sep 17, 2012
1 parent 7817974 commit a5e4253
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/rblineprof.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

#include <ruby.h>
#include <node.h>
Expand Down Expand Up @@ -91,8 +92,10 @@ profiler_hook(rb_event_t event, NODE *node, VALUE self, ID mid, VALUE klass)

/* grow the per-line array if necessary */
if (line >= sourcefile->nlines) {
long prev_nlines = sourcefile->nlines;
sourcefile->nlines = line + 100;
sourcefile->lines = realloc(sourcefile->lines, sizeof(uint64_t) * sourcefile->nlines);
memset(sourcefile->lines + prev_nlines, 0, sizeof(uint64_t) * (sourcefile->nlines - prev_nlines));
}

/* record the sample */
Expand Down

0 comments on commit a5e4253

Please sign in to comment.