Skip to content

Commit

Permalink
SAV reader: Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
evanmiller committed Jan 20, 2019
1 parent e5d0522 commit d2b7388
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/spss/readstat_sav.c
Expand Up @@ -60,12 +60,7 @@ void sav_ctx_free(sav_ctx_t *ctx) {
if (ctx->varinfo) {
int i;
for (i=0; i<ctx->var_index; i++) {
spss_varinfo_t *info = ctx->varinfo[i];
if (info) {
if (info->label)
free(info->label);
free(info);
}
spss_varinfo_free(ctx->varinfo[i]);
}
free(ctx->varinfo);
}
Expand Down
3 changes: 1 addition & 2 deletions src/spss/readstat_sav_read.c
Expand Up @@ -366,8 +366,7 @@ static readstat_error_t sav_read_variable_record(sav_ctx_t *ctx) {

cleanup:
if (retval != READSTAT_OK) {
if (info)
free(info);
spss_varinfo_free(info);
}

return retval;
Expand Down
8 changes: 8 additions & 0 deletions src/spss/readstat_spss.c
Expand Up @@ -73,6 +73,14 @@ int spss_varinfo_compare(const void *elem1, const void *elem2) {
return (offset > v->offset);
}

void spss_varinfo_free(spss_varinfo_t *info) {
if (info) {
if (info->label)
free(info->label);
free(info);
}
}

static readstat_value_t spss_boxed_value(double fp_value) {
readstat_value_t value = {
.type = READSTAT_TYPE_DOUBLE,
Expand Down
2 changes: 2 additions & 0 deletions src/spss/readstat_spss.h
Expand Up @@ -82,6 +82,8 @@ typedef struct spss_varinfo_s {
int spss_format(char *buffer, size_t len, spss_format_t *format);
int spss_varinfo_compare(const void *elem1, const void *elem2);

void spss_varinfo_free(spss_varinfo_t *info);

readstat_missingness_t spss_missingness_for_info(spss_varinfo_t *info);
readstat_variable_t *spss_init_variable_for_info(spss_varinfo_t *info, int index_after_skipping);

Expand Down

0 comments on commit d2b7388

Please sign in to comment.