summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-06-09 18:46:41 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-06-11 12:00:42 (GMT)
commit93316a9f1d687a86558daef529d583f5ae2be992 (patch)
treeae98719e4fe31f5a06a30a54208ce85ec200b5ae /src
parent7ae52660f58188a1bc9d8e69ff2711c6737c7e66 (diff)
downloadpowder-93316a9f1d687a86558daef529d583f5ae2be992.zip
powder-93316a9f1d687a86558daef529d583f5ae2be992.tar.gz
Fix a load of memory leaks
Also fix some compiler warnings (missing headers, wrong pointer type for modf, etc) and move variable declarations for Visual Studio.
Diffstat (limited to 'src')
-rw-r--r--src/console.c1
-rw-r--r--src/elements/neut.c6
-rw-r--r--src/elements/soap.c4
-rw-r--r--src/elements/stkm.c4
-rw-r--r--src/elements/stkm2.c8
-rw-r--r--src/graphics.c8
-rw-r--r--src/interface.c57
-rw-r--r--src/main.c6
-rw-r--r--src/misc.c1
9 files changed, 47 insertions, 48 deletions
diff --git a/src/console.c b/src/console.c
index 3fbcfb6..e4551d0 100644
--- a/src/console.c
+++ b/src/console.c
@@ -1,5 +1,6 @@
#include <powder.h>
#include <console.h>
+#include <math.h>
char pyready=1;
char pygood=1;
diff --git a/src/elements/neut.c b/src/elements/neut.c
index 20d4618..0d12a6d 100644
--- a/src/elements/neut.c
+++ b/src/elements/neut.c
@@ -1,11 +1,7 @@
#include <element.h>
-#if defined(WIN32) && !defined(__GNUC__)
-_inline int create_n_parts(int n, int x, int y, float vx, float vy, float temp, int t)
-#else
-inline int create_n_parts(int n, int x, int y, float vx, float vy, float temp, int t)//testing a new deut create part
-#endif
+int create_n_parts(int n, int x, int y, float vx, float vy, float temp, int t)//testing a new deut create part
{
int i, c;
n = (n/50);
diff --git a/src/elements/soap.c b/src/elements/soap.c
index 4ed10ac..e130e35 100644
--- a/src/elements/soap.c
+++ b/src/elements/soap.c
@@ -186,13 +186,13 @@ int update_SOAP(UPDATE_FUNC_ARGS)
if ((r&0xFF) == PT_OIL)
{
+ float ax, ay;
+
parts[i].vy -= 0.1f;
parts[i].vy *= 0.5f;
parts[i].vx *= 0.5f;
- float ax, ay;
-
ax = (parts[i].vx + parts[r>>8].vx)/2;
ay = (parts[i].vy + parts[r>>8].vy)/2;
diff --git a/src/elements/stkm.c b/src/elements/stkm.c
index 8b19406..01990f6 100644
--- a/src/elements/stkm.c
+++ b/src/elements/stkm.c
@@ -86,7 +86,7 @@ int update_STKM(UPDATE_FUNC_ARGS) {
//Go left
r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)];
- if (((int)(player[0])&0x01) == 0x01 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
+ if (((int)(player[0])&0x01) == 0x01 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
{
if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID
&& (r&0xFF) != PT_LNTG))
@@ -125,7 +125,7 @@ int update_STKM(UPDATE_FUNC_ARGS) {
//Go right
r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)];
- if (((int)(player[0])&0x02) == 0x02 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
+ if (((int)(player[0])&0x02) == 0x02 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
{
if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID
&& (r&0xFF) != PT_LNTG))
diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c
index 32f8619..a2731a6 100644
--- a/src/elements/stkm2.c
+++ b/src/elements/stkm2.c
@@ -86,10 +86,10 @@ int update_STKM2(UPDATE_FUNC_ARGS) {
//Go left
r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)];
- if (((int)(player2[0])&0x01) == 0x01 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
+ if (((int)(player2[0])&0x01) == 0x01 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
{
- if (r>=PT_NUM || ptypes[r&0xFF].state != ST_LIQUID
- && (r&0xFF) != PT_LNTG)
+ if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID
+ && (r&0xFF) != PT_LNTG))
{
if (pmap[(int)(player2[8]-1)][(int)(player2[7])])
{
@@ -125,7 +125,7 @@ int update_STKM2(UPDATE_FUNC_ARGS) {
//Go right
r = pmap[(int)(parts[i].y+10)][(int)(parts[i].x)];
- if (((int)(player2[0])&0x02) == 0x02 && ((r&0xFF>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
+ if (((int)(player2[0])&0x02) == 0x02 && (((r&0xFF)>=PT_NUM) || ptypes[r&0xFF].state != ST_GAS))
{
if (r>=PT_NUM || (ptypes[r&0xFF].state != ST_LIQUID
&& (r&0xFF) != PT_LNTG))
diff --git a/src/graphics.c b/src/graphics.c
index 669086a..8d06088 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -172,8 +172,8 @@ pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh)
{
fx = ((float)x)*((float)sw)/((float)rw);
fy = ((float)y)*((float)sh)/((float)rh);
- fxc = modf(fx, &intp);
- fyc = modf(fy, &intp);
+ fxc = modff(fx, &intp);
+ fyc = modff(fy, &intp);
fxceil = (int)ceil(fx);
fyceil = (int)ceil(fy);
if (fxceil>=sw) fxceil = sw-1;
@@ -212,8 +212,8 @@ pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh)
{
fx = ((float)x)*((float)sw)/((float)rw);
fy = ((float)y)*((float)sh)/((float)rh);
- fxc = modf(fx, &intp);
- fyc = modf(fy, &intp);
+ fxc = modff(fx, &intp);
+ fyc = modff(fy, &intp);
fxceil = (int)ceil(fx);
fyceil = (int)ceil(fy);
if (fxceil>=sw) fxceil = sw-1;
diff --git a/src/interface.c b/src/interface.c
index b26fbae..62c196e 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1628,31 +1628,11 @@ int save_name_ui(pixel *vid_buf)
ui_edit_process(mx, my, b, &ed2);
ui_checkbox_process(mx, my, b, bq, &cb);
- if (b && !bq && ((mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36) ||
+ if ((b && !bq && ((mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36) ||
(mx>=x0 && mx<x0+192 && my>=y0+74+YRES/4 && my<y0+90+YRES/4)))
+ || sdl_key==SDLK_RETURN)
{
- free(th);
- if (!ed.str[0])
- return 0;
- nd = strcmp(svf_name, ed.str) || !svf_own;
- strncpy(svf_name, ed.str, 63);
- svf_name[63] = 0;
- strncpy(svf_description, ed2.str, 254);
- svf_description[254] = 0;
- if (nd)
- {
- strcpy(svf_id, "");
- strcpy(svf_tags, "");
- }
- svf_open = 1;
- svf_own = 1;
- svf_publish = cb.checked;
- return nd+1;
- }
-
- if (sdl_key==SDLK_RETURN)
- {
- free(th);
+ if (th) free(th);
if (!ed.str[0])
return 0;
nd = strcmp(svf_name, ed.str) || !svf_own;
@@ -1668,6 +1648,7 @@ int save_name_ui(pixel *vid_buf)
svf_open = 1;
svf_own = 1;
svf_publish = cb.checked;
+ free(old_vid);
return nd+1;
}
if (sdl_key==SDLK_ESCAPE)
@@ -1677,7 +1658,8 @@ int save_name_ui(pixel *vid_buf)
ed.focus = 0;
}
}
- free(th);
+ if (th) free(th);
+ free(old_vid);
return 0;
}
@@ -3123,6 +3105,7 @@ finish:
strcpy(search_expr, ed.str);
+ free(v_buf);
return 0;
}
@@ -3196,8 +3179,8 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
float ryf;
char *uri, *uri_2, *o_uri, *uri_3;
- void *data, *info_data, *thumb_data_full;
- save_info *info = malloc(sizeof(save_info));
+ void *data = NULL, *info_data, *thumb_data_full;
+ save_info *info = calloc(sizeof(save_info), 1);
void *http = NULL, *http_2 = NULL, *http_3 = NULL;
int lasttime = TIMEOUT;
int status, status_2, info_ready = 0, data_ready = 0, thumb_data_ready = 0;
@@ -3605,9 +3588,10 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
// Do Open!
status = parse_save(data, data_size, 1, 0, 0, bmap, fvx, fvy, signs, parts, pmap);
if (!status) {
- //if(svf_last)
- //free(svf_last);
+ if(svf_last)
+ free(svf_last);
svf_last = data;
+ data = NULL; //so we don't free it when returning
svf_lsize = data_size;
svf_open = 1;
@@ -3677,6 +3661,12 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
http_async_req_close(http);
if (http_2)
http_async_req_close(http_2);
+ if (http_3)
+ http_async_req_close(http_3);
+ info_parse("", info);
+ free(info);
+ free(old_vid);
+ if (data) free(data);
return retval;
}
@@ -3685,6 +3675,17 @@ int info_parse(char *info_data, save_info *info)
int i,j;
char *p,*q,*r,*s,*vu,*vd,*pu,*sd;
+ if (info->title) free(info->title);
+ if (info->name) free(info->name);
+ if (info->author) free(info->author);
+ if (info->date) free(info->date);
+ if (info->description) free(info->description);
+ if (info->tags) free(info->tags);
+ for (i=0;i<6;i++)
+ {
+ if (info->comments[i]) free(info->comments[i]);
+ if (info->commentauthors[i]) free(info->commentauthors[i]);
+ }
memset(info, 0, sizeof(save_info));
if (!info_data || !*info_data)
diff --git a/src/main.c b/src/main.c
index 5a22208..ea32d3a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1378,7 +1378,7 @@ int set_scale(int scale, int kiosk){
return 1;
}
-void update_grav_async()
+void* update_grav_async(void* unused)
{
int done = 0;
int thread_done = 0;
@@ -2044,7 +2044,7 @@ int main(int argc, char *argv[])
free(load_data);
}
}
- if (sdl_key=='s' && (sdl_mod & (KMOD_CTRL)) || (sdl_key=='s' && !isplayer2))
+ if (sdl_key=='s' && ((sdl_mod & (KMOD_CTRL)) || !isplayer2))
{
if (it > 50)
it = 50;
@@ -2178,7 +2178,7 @@ int main(int argc, char *argv[])
bsy = 0;
}
}
- if (sdl_key=='d'&&(sdl_mod & (KMOD_CTRL)) || (sdl_key=='d' && !isplayer2))
+ if (sdl_key=='d' && ((sdl_mod & (KMOD_CTRL)) || !isplayer2))
DEBUG_MODE = !DEBUG_MODE;
if (sdl_key=='i')
{
diff --git a/src/misc.c b/src/misc.c
index 2c84baf..cf0bd7c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -3,6 +3,7 @@
#include <string.h>
#include <regex.h>
#include <sys/types.h>
+#include <math.h>
#include "misc.h"
#include "defines.h"
#include "interface.h"