author | erik <erik> | 2007-01-24 19:46:19 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-24 19:46:19 (UTC) |
commit | a017bf21dd89159052f2f7a3fbc043a24956c08c (patch) (unidiff) | |
tree | 008be2b62ee5487dc55b8a7c7f043c94268f8362 /noncore/net/ftplib/ftplib.c | |
parent | a4a7bd22feb060a80e20c81cded43cc24f5cd423 (diff) | |
download | opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.zip opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.gz opie-a017bf21dd89159052f2f7a3fbc043a24956c08c.tar.bz2 |
Every file in this commit has a memory leak of some kind or another. I think
all of them are minor and should not effect properly running code. But if I
were you I would give libstocks and the stockticker plugin in Today a wide
berth. That library is atrocious.
-rw-r--r-- | noncore/net/ftplib/ftplib.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/noncore/net/ftplib/ftplib.c b/noncore/net/ftplib/ftplib.c index efcd6f0..addf9d2 100644 --- a/noncore/net/ftplib/ftplib.c +++ b/noncore/net/ftplib/ftplib.c | |||
@@ -1127,97 +1127,101 @@ GLOBALDEF int FtpPwd(char *path, int max, netbuf *nControl) | |||
1127 | { | 1127 | { |
1128 | int l = max; | 1128 | int l = max; |
1129 | char *b = path; | 1129 | char *b = path; |
1130 | char *s; | 1130 | char *s; |
1131 | if (!FtpSendCmd("PWD",'2',nControl)) | 1131 | if (!FtpSendCmd("PWD",'2',nControl)) |
1132 | return 0; | 1132 | return 0; |
1133 | s = strchr(nControl->response, '"'); | 1133 | s = strchr(nControl->response, '"'); |
1134 | if (s == NULL) | 1134 | if (s == NULL) |
1135 | return 0; | 1135 | return 0; |
1136 | s++; | 1136 | s++; |
1137 | while ((--l) && (*s) && (*s != '"')) | 1137 | while ((--l) && (*s) && (*s != '"')) |
1138 | *b++ = *s++; | 1138 | *b++ = *s++; |
1139 | *b++ = '\0'; | 1139 | *b++ = '\0'; |
1140 | return 1; | 1140 | return 1; |
1141 | } | 1141 | } |
1142 | 1142 | ||
1143 | /* | 1143 | /* |
1144 | * FtpXfer - issue a command and transfer data | 1144 | * FtpXfer - issue a command and transfer data |
1145 | * | 1145 | * |
1146 | * return 1 if successful, 0 otherwise | 1146 | * return 1 if successful, 0 otherwise |
1147 | */ | 1147 | */ |
1148 | static int FtpXfer(const char *localfile, const char *path, | 1148 | static int FtpXfer(const char *localfile, const char *path, |
1149 | netbuf *nControl, int typ, int mode) | 1149 | netbuf *nControl, int typ, int mode) |
1150 | { | 1150 | { |
1151 | int l,c; | 1151 | int l,c; |
1152 | char *dbuf; | 1152 | char *dbuf; |
1153 | FILE *local = NULL; | 1153 | FILE *local = NULL; |
1154 | netbuf *nData; | 1154 | netbuf *nData; |
1155 | int rv=1; | 1155 | int rv=1; |
1156 | 1156 | ||
1157 | if (localfile != NULL) | 1157 | if (localfile != NULL) |
1158 | { | 1158 | { |
1159 | char ac[4] = "w"; | 1159 | char ac[4] = "w"; |
1160 | if (typ == FTPLIB_FILE_WRITE) | 1160 | if (typ == FTPLIB_FILE_WRITE) |
1161 | ac[0] = 'r'; | 1161 | ac[0] = 'r'; |
1162 | if (mode == FTPLIB_IMAGE) | 1162 | if (mode == FTPLIB_IMAGE) |
1163 | ac[1] = 'b'; | 1163 | ac[1] = 'b'; |
1164 | local = fopen(localfile, ac); | 1164 | local = fopen(localfile, ac); |
1165 | if (local == NULL) | 1165 | if (local == NULL) |
1166 | { | 1166 | { |
1167 | strncpy(nControl->response, strerror(errno), | 1167 | strncpy(nControl->response, strerror(errno), |
1168 | sizeof(nControl->response)); | 1168 | sizeof(nControl->response)); |
1169 | return 0; | 1169 | return 0; |
1170 | } | 1170 | } |
1171 | } | 1171 | } |
1172 | if (local == NULL) | 1172 | if (local == NULL) |
1173 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; | 1173 | local = (typ == FTPLIB_FILE_WRITE) ? stdin : stdout; |
1174 | if (!FtpAccess(path, typ, mode, nControl, &nData)) | 1174 | if (!FtpAccess(path, typ, mode, nControl, &nData)) |
1175 | { | ||
1176 | if (localfile != NULL) | ||
1177 | fclose(local); | ||
1175 | return 0; | 1178 | return 0; |
1179 | } | ||
1176 | dbuf = malloc(FTPLIB_BUFSIZ); | 1180 | dbuf = malloc(FTPLIB_BUFSIZ); |
1177 | if (typ == FTPLIB_FILE_WRITE) | 1181 | if (typ == FTPLIB_FILE_WRITE) |
1178 | { | 1182 | { |
1179 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) | 1183 | while ((l = fread(dbuf, 1, FTPLIB_BUFSIZ, local)) > 0) |
1180 | if ((c = FtpWrite(dbuf, l, nData)) < l) | 1184 | if ((c = FtpWrite(dbuf, l, nData)) < l) |
1181 | { | 1185 | { |
1182 | printf("short write: passed %d, wrote %d\n", l, c); | 1186 | printf("short write: passed %d, wrote %d\n", l, c); |
1183 | rv = 0; | 1187 | rv = 0; |
1184 | break; | 1188 | break; |
1185 | } | 1189 | } |
1186 | } | 1190 | } |
1187 | else | 1191 | else |
1188 | { | 1192 | { |
1189 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) | 1193 | while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) |
1190 | if (fwrite(dbuf, 1, l, local) <= 0) | 1194 | if (fwrite(dbuf, 1, l, local) <= 0) |
1191 | { | 1195 | { |
1192 | perror("localfile write"); | 1196 | perror("localfile write"); |
1193 | rv = 0; | 1197 | rv = 0; |
1194 | break; | 1198 | break; |
1195 | } | 1199 | } |
1196 | } | 1200 | } |
1197 | free(dbuf); | 1201 | free(dbuf); |
1198 | fflush(local); | 1202 | fflush(local); |
1199 | if (localfile != NULL) | 1203 | if (localfile != NULL) |
1200 | fclose(local); | 1204 | fclose(local); |
1201 | FtpClose(nData); | 1205 | FtpClose(nData); |
1202 | return rv; | 1206 | return rv; |
1203 | } | 1207 | } |
1204 | 1208 | ||
1205 | /* | 1209 | /* |
1206 | * FtpNlst - issue an NLST command and write response to output | 1210 | * FtpNlst - issue an NLST command and write response to output |
1207 | * | 1211 | * |
1208 | * return 1 if successful, 0 otherwise | 1212 | * return 1 if successful, 0 otherwise |
1209 | */ | 1213 | */ |
1210 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, | 1214 | GLOBALDEF int FtpNlst(const char *outputfile, const char *path, |
1211 | netbuf *nControl) | 1215 | netbuf *nControl) |
1212 | { | 1216 | { |
1213 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); | 1217 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR, FTPLIB_ASCII); |
1214 | } | 1218 | } |
1215 | 1219 | ||
1216 | /* | 1220 | /* |
1217 | * FtpDir - issue a LIST command and write response to output | 1221 | * FtpDir - issue a LIST command and write response to output |
1218 | * | 1222 | * |
1219 | * return 1 if successful, 0 otherwise | 1223 | * return 1 if successful, 0 otherwise |
1220 | */ | 1224 | */ |
1221 | GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) | 1225 | GLOBALDEF int FtpDir(const char *outputfile, const char *path, netbuf *nControl) |
1222 | { | 1226 | { |
1223 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); | 1227 | return FtpXfer(outputfile, path, nControl, FTPLIB_DIR_VERBOSE, FTPLIB_ASCII); |