summaryrefslogtreecommitdiff
path: root/math/libocas/files/patch-linclass.c
blob: 95417fe62ba623980cec4b9db69c07878a512915 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
--- linclassif.c.orig	2010-05-05 08:55:55.000000000 -0400
+++ linclassif.c	2011-10-06 05:11:23.000000000 -0400
@@ -62,7 +62,7 @@
   uint32_t i, j;
   int len;
   int recognized;
-  int exitflag = 0;
+  int exitflag = 1;
   int verb;
   int binary_problem;
   int output_type;
@@ -101,6 +101,8 @@
   feat_idx = NULL;
   W = NULL;
   W0 = 0;
+  input_fname = NULL;
+  model_fname = NULL;
   output_fname = NULL;
   nClassErrors = NULL;
   nClass = NULL;
@@ -275,6 +277,7 @@
   if(fgets(line,LIBSLF_MAXLINELEN, fid) == NULL ) 
   {
     fprintf(stderr,"Empty example file.\n");
+    fclose(fid);
     goto clean_up;
   }
   else
@@ -312,6 +315,7 @@
     if( tmp_nCols != nCols)
     {
       fprintf(stderr,"Error: Model file contains lines with different number of colums.\n");
+      fclose(fid);
       goto clean_up;
     }
 
@@ -340,6 +344,7 @@
     if(W == NULL)
     {
       fprintf(stderr,"Not enough memory for vector W.\n");
+      fclose(fid);
       goto clean_up;
     }
 
@@ -355,6 +360,7 @@
       if(fgets(line,LIBSLF_MAXLINELEN, fid) == NULL ) 
       {
         fprintf(stderr,"Model file corrupted.\n");
+	fclose(fid);
         goto clean_up;
       }
 
@@ -364,6 +370,7 @@
       if(val == 0 && begptr == endptr)
       {
         fprintf(stderr,"Model file corrupted.\n");
+	fclose(fid);
         goto clean_up;
       }
 
@@ -388,6 +395,7 @@
     if(W == NULL)
     {
       fprintf(stderr,"Not enough memory for matrix W.\n");
+      fclose(fid);
       goto clean_up;
     }
 
@@ -403,6 +411,7 @@
       if(fgets(line,LIBSLF_MAXLINELEN, fid) == NULL ) 
       {
         fprintf(stderr,"Model file corrupted.\n");
+	fclose(fid);
         goto clean_up;
       }
 
@@ -414,6 +423,7 @@
         if(val == 0 && begptr == endptr)
         {
           fprintf(stderr,"Model file corrupted.\n");
+	  fclose(fid);
           goto clean_up;
         }
         begptr = endptr;
@@ -458,7 +468,7 @@
   else
   {
     fout = fopen(output_fname, "w+");
-    if(fid == NULL) {
+    if(fout == NULL) {
       fprintf(stderr,"Cannot open output file.\n");
       perror("fopen error ");
       fclose(fid);
@@ -478,6 +488,9 @@
   if(nClassErrors == NULL)
   {
     fprintf(stderr,"Not enough memory for vector nClassError.\n");
+    fclose(fid);
+    if(output_fname != NULL)
+      fclose(fout);
     goto clean_up;
   }
 
@@ -485,6 +498,9 @@
   if(nClass == NULL)
   {
     fprintf(stderr,"Not enough memory for vector nClass.\n");
+    fclose(fid);
+    if(output_fname != NULL)
+      fclose(fout);
     goto clean_up;
   }
   
@@ -505,6 +521,9 @@
       {
          fprintf(stderr,"Parsing error on line %ld .\n", line_cnt);
          fprintf(stderr,"Probably defective input file.\n");
+	 fclose(fid);
+	 if(output_fname != NULL)
+	   fclose(fout);
          goto clean_up;
       }
 
@@ -612,12 +631,16 @@
 
 
   fclose(fid);
-  fclose(fout);
+  if(output_fname != NULL)
+    fclose(fout);
 
-  exitflag = 1;
+  exitflag = 0;
   
 clean_up:
 
+  free(input_fname);
+  free(model_fname);
+  free(output_fname);
   free(W);
   free(line);
   free(feat_val);