Unverified Commit a1539a99 authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Properly cleanup on failure to open a file

parent 00053b2a
......@@ -13,12 +13,13 @@ int main(int argc, char **argv) {
}
fin = fopen(argv[1], "r");
if (!fin) {
printf("cannout open input file: %s\n", argv[1]);
fprintf(stderr, "cannot open input file: %s\n", argv[1]);
return 1;
}
enc = ope_create_file(argv[2], 48000, 2, 0, &error);
if (!enc) {
printf("cannout open output file: %s\n", argv[2]);
fprintf(stderr, "cannout open output file: %s\n", argv[2]);
fclose(fin);
return 1;
}
ope_add_comment(enc, "ARTIST", "Someone");
......
......@@ -166,7 +166,8 @@ int stdio_write(void *user_data, const unsigned char *ptr, int len) {
int stdio_close(void *user_data) {
struct StdioObject *obj = (struct StdioObject*)user_data;
int ret = fclose(obj->file);
int ret = 0;
if (obj->file) ret = fclose(obj->file);
free(obj);
return ret;
}
......@@ -188,8 +189,7 @@ OggOpusEnc *ope_create_file(const char *path, int rate, int channels, int family
obj->file = fopen(path, "wb");
if (!obj->file) {
if (error) *error = OPE_CANNOT_OPEN;
/* FIXME: Destroy the encoder properly. */
free(obj);
ope_destroy(enc);
return NULL;
}
return enc;
......@@ -624,7 +624,7 @@ void ope_destroy(OggOpusEnc *enc) {
if (enc->chaining_keyframe) free(enc->chaining_keyframe);
free(enc->buffer);
#ifdef USE_OGGP
oggp_destroy(enc->oggp);
if (enc->oggp) oggp_destroy(enc->oggp);
#endif
opus_multistream_encoder_destroy(enc->st);
if (enc->re) speex_resampler_destroy(enc->re);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment