Changeset 8452


Ignore:
Timestamp:
03/02/13 12:55:35 (8 years ago)
Author:
gf
Message:

Do not forget to close open file on error.

Patch by DaytonaHack.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/module-stat.c

    r8411 r8452  
    121121    }
    122122   
    123     if (!cs_malloc(&line, LINESIZE))
     123    if (!cs_malloc(&line, LINESIZE)) {
     124        fclose(file);
    124125        return;
    125    
     126    }
     127
    126128    setvbuf(file, NULL, _IOFBF, 128*1024);
    127129
  • trunk/oscam-emm.c

    r8411 r8452  
    226226        int32_t emm_length = ((ep->emm[1] & 0x0f) << 8) | ep->emm[2];
    227227        strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", &timeinfo);
    228         if (!(fp = fopen(get_emmlog_filename(token, sizeof(token), aureader->label, "log"), "a"))) {
     228        fp = fopen(get_emmlog_filename(token, sizeof(token), aureader->label, "log"), "a");
     229        if (!fp) {
    229230            rdr_log(aureader, "ERROR: Cannot open file '%s' (errno=%d: %s)\n", token, errno, strerror(errno));
    230         } else if (cs_malloc(&tmp2, (emm_length + 3) * 2 + 1)) {
    231             fprintf(fp, "%s   %s   ", buf, cs_hexdump(0, ep->hexserial, 8, tmp, sizeof(tmp)));
    232             fprintf(fp, "%s\n", cs_hexdump(0, ep->emm, emm_length + 3, tmp2, (emm_length + 3) * 2 + 1));
    233             free(tmp2);
     231        } else {
     232            if (cs_malloc(&tmp2, (emm_length + 3) * 2 + 1)) {
     233                fprintf(fp, "%s   %s   ", buf, cs_hexdump(0, ep->hexserial, 8, tmp, sizeof(tmp)));
     234                fprintf(fp, "%s\n", cs_hexdump(0, ep->emm, emm_length + 3, tmp2, (emm_length + 3) * 2 + 1));
     235                free(tmp2);
     236                rdr_log(aureader, "Successfully added EMM to %s", token);
     237            }
    234238            fclose(fp);
    235             rdr_log(aureader, "Successfully added EMM to %s", token);
    236         }
    237         if (!(fp = fopen(get_emmlog_filename(token, sizeof(token), aureader->label, "bin"), "ab"))) {
     239        }
     240        fp = fopen(get_emmlog_filename(token, sizeof(token), aureader->label, "bin"), "ab");
     241        if (!fp) {
    238242            rdr_log(aureader, "ERROR: Cannot open file '%s' (errno=%d: %s)\n", token, errno, strerror(errno));
    239243        } else {
Note: See TracChangeset for help on using the changeset viewer.