Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openUpdateImage() should cleanup upon BADDIMS #289

Open
jamienoss opened this issue Jan 9, 2018 · 0 comments
Open

openUpdateImage() should cleanup upon BADDIMS #289

jamienoss opened this issue Jan 9, 2018 · 0 comments

Comments

@jamienoss
Copy link
Contributor

jamienoss commented Jan 9, 2018

The following code should cleanup correctly src:

...
/* get the dimensions and type */
        fits_get_img_dim(iodesc->ff, &no_dims, &status);
        fits_get_img_equivtype(iodesc->ff, &iodesc->type, &status);
        fits_get_img_size(iodesc->ff, 2, iodesc->dims, &status);
        if (status) {
            ioerr(BADDIMS, iodesc, status);
            return NULL;
        }
        if (no_dims == 2) {
            /* Nothing */
        } else if (no_dims == 1) {
            iodesc->dims[1] = 0;
        } else if (no_dims == 0) {
            iodesc->dims[0] = 0;
            iodesc->dims[1] = 0;
        } else {
            ioerr(BADDIMS, iodesc, 0);
            return NULL;
        }
...

should be:

...
/* get the dimensions and type */
        fits_get_img_dim(iodesc->ff, &no_dims, &status);
        fits_get_img_equivtype(iodesc->ff, &iodesc->type, &status);
        fits_get_img_size(iodesc->ff, 2, iodesc->dims, &status);
        if (status) {
            ioerr(BADDIMS, iodesc, status);
            free(iodesc->extname);
            free(iodesc->filename);
            free(iodesc);
            return NULL;
        }
        if (no_dims == 2) {
            /* Nothing */
        } else if (no_dims == 1) {
            iodesc->dims[1] = 0;
        } else if (no_dims == 0) {
            iodesc->dims[0] = 0;
            iodesc->dims[1] = 0;
        } else {
            ioerr(BADDIMS, iodesc, 0);
            free(iodesc->extname);
            free(iodesc->filename);
            free(iodesc);
            return NULL;
        }
...

There may be an existing helper func that could be used here.

In addition, the free(tmp) should also nullify tmp - src.

The above may not be everything needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants