Skip to content

Commit 6a02046

Browse files
committed
Fix lack of matching SDL_free for SDL_GetClipboardText.
1 parent c022746 commit 6a02046

8 files changed

+37
-4
lines changed

src/editor/clipboard.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ __M_BEGIN_DECLS
2727
void copy_buffer_to_clipboard(char **buffer, int lines, int total_length);
2828

2929
char *get_clipboard_buffer(void);
30+
void free_clipboard_buffer(char *buffer);
3031

3132
__M_END_DECLS
3233

src/editor/clipboard_carbon.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ char *get_clipboard_buffer(void)
125125
src_data = (char *)CFDataGetBytePtr(flavorData);
126126
length = (size_t)CFDataGetLength(flavorData);
127127

128-
dest_data = cmalloc(length + 1);
128+
dest_data = (char *)cmalloc(length + 1);
129129
memcpy(dest_data, src_data, length);
130130
dest_data[length] = 0;
131131

@@ -137,3 +137,8 @@ char *get_clipboard_buffer(void)
137137
CFRelease(clipboard);
138138
return dest_data;
139139
}
140+
141+
void free_clipboard_buffer(char *buffer)
142+
{
143+
free(buffer);
144+
}

src/editor/clipboard_cocoa.m

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ void copy_buffer_to_clipboard(char **buffer, int lines, int total_length)
115115
goto err;
116116

117117
size_t buf_len = [chrdata length];
118-
char *buf = cmalloc(buf_len + 1);
118+
char *buf = (char *)cmalloc(buf_len + 1);
119119

120120
[chrdata getBytes:buf length:buf_len];
121121
buf[buf_len] = '\0';
@@ -126,3 +126,8 @@ void copy_buffer_to_clipboard(char **buffer, int lines, int total_length)
126126
[pool release];
127127
return NULL;
128128
}
129+
130+
void free_clipboard_buffer(char *buffer)
131+
{
132+
free(buffer);
133+
}

src/editor/clipboard_null.c

+6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@
1818
*/
1919

2020
#include "clipboard.h"
21+
#include <stdlib.h>
2122

2223
void copy_buffer_to_clipboard(char **buffer, int lines, int total_length) {}
2324

2425
char *get_clipboard_buffer(void)
2526
{
2627
return NULL;
2728
}
29+
30+
void free_clipboard_buffer(char *buffer)
31+
{
32+
free(buffer);
33+
}

src/editor/clipboard_sdl2.c

+5
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@ char *get_clipboard_buffer(void)
5858
{
5959
return SDL_GetClipboardText();
6060
}
61+
62+
void free_clipboard_buffer(char *buffer)
63+
{
64+
SDL_free(buffer);
65+
}

src/editor/clipboard_win32.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ char *get_clipboard_buffer(void)
8686
// CF_TEXT is guaranteed to be null-terminated.
8787
length = strlen(src_data);
8888

89-
dest_data = cmalloc(length + 1);
89+
dest_data = (char *)cmalloc(length + 1);
9090
strcpy(dest_data, src_data);
9191

9292
GlobalUnlock(global_memory);
@@ -97,3 +97,8 @@ char *get_clipboard_buffer(void)
9797

9898
return NULL;
9999
}
100+
101+
void free_clipboard_buffer(char *buffer)
102+
{
103+
free(buffer);
104+
}

src/editor/clipboard_x11.c

+5
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,8 @@ char *get_clipboard_buffer(void)
202202
XUnlockDisplay(display);
203203
return dest_data;
204204
}
205+
206+
void free_clipboard_buffer(char *buffer)
207+
{
208+
free(buffer);
209+
}

src/editor/robo_ed.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,8 @@ static void paste_buffer(struct robot_editor_context *rstate)
15371537
#endif
15381538
}
15391539

1540-
free(ext_buffer);
1540+
/* This may need SDL_free if it was allocated by SDL. */
1541+
free_clipboard_buffer(ext_buffer);
15411542
}
15421543
else
15431544

0 commit comments

Comments
 (0)